IWETHEY v. 0.3.0 | TODO
1,095 registered users | 0 active users | 1 LpH | Statistics
Login | Create New User
IWETHEY Banner

Welcome to IWETHEY!

New Not Python specific...
...but there are a couple of ways to generate unique names - all predicated on having a number tacked onto the end of a string.

First, use a dictionary item to look up the next available number and increment the number immediately. The object names will be objectName0, objectName1,...objectName[n]. The advantage is that it makes a good way to keep track of the number of objects being allocated. The downside is that the retrieval and update of the index must be atomic (i.e. wrapped in a transaction or locked via a semaphore whilst incrementing).

Second, just ask for a random number. The likelihood of getting the same number twice is small but will require a check to see if the object name is already in use. Also requires a lock whilst checking for the new object name. Not recommended.

Or just use the system clock to generate the number. The clock should never be the same (of course, it depends on the resolution of the clock and whether it's possible to get the same value twice).

A final method is to set aside a static method (i.e. a class level method) that is used to retrieve object names. The method does nothing but increment a class level int variable and returns the variable name as a string.
New I was thinking about that but not sure how to implement
Tom Sinclair
Speaker-to-Suits
New Re: I was thinking about that but not sure how to implement
name = "myobject"
i = 0
for parrot in myParrots:
    do_something(parrot, name + i)
    i = i + 1
Regards,

-scott anderson
New Thanks!
Tom Sinclair
Speaker-to-Suits
     Variable names in Python - (tjsinclair) - (4)
         Not Python specific... - (ChrisR) - (3)
             I was thinking about that but not sure how to implement -NT - (tjsinclair) - (2)
                 Re: I was thinking about that but not sure how to implement - (admin) - (1)
                     Thanks! -NT - (tjsinclair)

No, THIS is the funniest LRPDism...
34 ms