Re: Newbie question regarding string.split()
kevinliu23 wrote:
> Hey guys,
>
> So I have a question regarding the split() function in the string
> module. Let's say I have an string...
>
> input = "2b 3 4bx 5b 2c 4a 5a 6"
> projectOptions = (input.replace(" ", "")).split('2')
> print projectOptions
>
> ['', 'b34bx5b', 'c4a5a6']
>
> My question is, why is the first element of projectOptions an empty
> string? What can I do so that the first element is not an empty
> string? but the 'b34bx5b' string as I expected?
>
> Thanks so much guys. :)
>
split on c instead
--
http://mail.python.org/mailman/listinfo/python-list
Testing GUI's
Can any of you guy's out there point me to information on automating GUI's that use Tkinter. I would like to find out more and possibly get involved if there are any projects under development. Thanks in advance. Steve -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Newbie Suggestions
[EMAIL PROTECTED] wrote: > I'm a mechanical engineer with little experience programming. I've > used C++ and machine language for getting micro-controllers to work > and thats about it. I work allot with software developers at my job > and can read C++ code pretty good (ie. I understand whats going on). > Does anyone have any good tips or resources for someone interested in > learning PYTHON. This is purely for hobby purposes and I'd like to > expose my kids to a programing language too. If any one has any > helpful books, tips or suggestions please let me know. I have > Windows, MAC and Linux box's at my house but I'm a primarily a MAC > user. > I was once a newbie too. I started with the Python Tutorial which is on the Python Website and found it to be a good starting point. http://docs.python.org/tut/tut.html Have a go with this and see how you get on. There are lots of resources at http://www.python.org, including distributions of the latest version of the python interpreter, which you should install (if you have not already) before attempting the tutorials. -- http://mail.python.org/mailman/listinfo/python-list
Re: Python Newbie Suggestions
Michael Tobis wrote: > I think > > http://www.diveintopython.org/ > > would be very suitable for you. > > mt > > > > I disagree here. The site was last updated in 2004; its out of date. For a newbie any material referenced should be current and include what is available in Python 2.5. -- http://mail.python.org/mailman/listinfo/python-list
Re: Generating a unique identifier
On Sep 7, 1:03 pm, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote: > I have an application that will be producing many instances, using them > for a while, then tossing them away, and I want each one to have a unique > identifier that won't be re-used for the lifetime of the Python session. > > I can't use the id() of the object, because that is only guaranteed to be > unique during the lifetime of the object. > > For my application, it doesn't matter if the ids are predictable, so I > could do something as simple as this: > > def unique_id(): > n = 1234567890 > while True: > yield n > n += 1 > > unique_id = unique_id() > > while Application_Is_Running: > make_an_object(id=unique_id()) > do_stuff_with_objects() > delete_some_of_them() > > which is easy enough, but I thought I'd check if there was an existing > solution in the standard library that I missed. Also, for other > applications, I might want them to be rather less predictable. > > -- > Steven. This is very simple. Use a class variable that increments every time a new object is created. If you need to use it in a number of different types of object then you could use the code below in a metaclass and tag all of your classes with the metaclass. Unless you are making billions of objects then i think that this should suffice. class MyObj: id_count = 0 def __init__(self): self.id = self.id_count MyObj.id_count += 1 print self.id, MyObj.id_count MyObj() MyObj() -- http://mail.python.org/mailman/listinfo/python-list
