Convert PySerial to python 3.0
I am just messing around trying to get pyserial to work with 3.0.
I am stuck on this line:
if type(port) in [type(''), type(u'')]
how can I convert this to 3.0? I tried changing the u to a d that did
not do anything.
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
Re: Convert PySerial to python 3.0
On Feb 24, 10:55 pm, Chris Rebert wrote:
> On Tue, Feb 24, 2009 at 7:46 PM, Seth wrote:
> > I am just messing around trying to get pyserial to work with 3.0.
>
> > I am stuck on this line:
>
> > if type(port) in [type(''), type(u'')]
>
> > how can I convert this to 3.0? I tried changing the u to a d that did
> > not do anything.
>
> Looks like it's doing the equivalent of the pre-3.0-ism
> `isinstance(port, basestring)`, but in a roundabout way.
> However, since basestring doesn't exist in 3.0, either:
>
> if isinstance(port, str):
>
> Or
>
> if isinstance(port, bytes):
>
> would be the appropriate replacement. Depends (obviously) on whether
> 'port' is supposed to be unicode or a byte sequence.
> Without more context, I can't really say which is what you want.
>
> Cheers,
> Chris
>
> --
> Follow the path of the Iguana...http://rebertia.com
I implemented "if isinstance(port, str): " that seems to work for now.
Currently I am running into:
err, n = win32file.WriteFile(self.hComPort, data,
self._overlappedWrite)
TypeError: expected an object with a buffer interface
Thanks
--
http://mail.python.org/mailman/listinfo/python-list
Re: Convert PySerial to python 3.0
I tried all three ways you guys listed nothing seems to convert the
string to bytes.
It may have to do with the makeDeviceName function, but I can't find
where that is defined.
Any thoughts??
Here is the whole block of code:
if type(port) in (str, bytes): #strings are taken directly
Originally: if type(port) in [type(''), type(u'')]
self.portstr = port
else:
self.portstr = self.makeDeviceName(port)
On Feb 25, 8:47 am, Christian Heimes wrote:
> Seth wrote:
> > I implemented "if isinstance(port, str): " that seems to work for now.
>
> > Currently I am running into:
>
> > err, n = win32file.WriteFile(self.hComPort, data,
> > self._overlappedWrite)
> > TypeError: expected an object with a buffer interface
>
> Unicode objects (in Py3k: str) don't implement the buffer interface. You
> have to apply a bytes or bytearray instance.
>
> Christian
--
http://mail.python.org/mailman/listinfo/python-list
Re: Convert PySerial to python 3.0
This is not my code and I am fairly new to Python. I did not know how
much it would take to convert pyserial to 3.0. Someone more
knowledgeable than me could do it better and faster. I just want to
see if I could help get it to work.
I was wrong, it seems that if type(port) in (str, bytes): or isinstance
(port, str) works just fine for setting the ports.
The issue now is reading and writing the data.
I got the read() to kind of work with:
bytes(buf[:n]) replacing str(buf[:n])
but with readline() it seems to be missing the '\n' because it just
runs indefinitely( I can see the \n if I read enough bytes with read()
write seems to be related to a win32 issue. win32file.WriteFile does
not like anything I convert it to:
str gives the buffer error
bytes gives a "string argument without an encoding" error
Sorry for the confusion, I just want to be able to use all Py3k on
this project that I am working on and pyserial has not been converted
so I just started messing around with it.
Thanks for the help.
Seth
On Feb 25, 10:16 am, Christian Heimes wrote:
> Seth wrote:
> > I tried all three ways you guys listed nothing seems to convert the
> > string to bytes.
>
> > It may have to do with the makeDeviceName function, but I can't find
> > where that is defined.
>
> > Any thoughts??
>
> > Here is the whole block of code:
>
> > if type(port) in (str, bytes): #strings are taken directly
> > Originally: if type(port) in [type(''), type(u'')]
> > self.portstr = port
> > else:
> > self.portstr = self.makeDeviceName(port)
>
> str and bytes are two totally unrelated things in Python 3.0. You can no
> longer treat them equally like str and unicode in Python 2.x. Your could
> should not work under Python 3.0 anyway. u'' is invalid in 3.x.
>
> Also please don't use ugly type checks like type(something) == type('').
> Starting with Python 2.2 you should use isinstance, for example
> isinstance(number, (int, long)).
>
> Christian
--
http://mail.python.org/mailman/listinfo/python-list
shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5
There is something you could possibly help me with. We have a code that creates a simple Python shelve database. We are able to serialize objects and store them in the dbm file. This seem to work the same on Windows XP Python 2.5, Ubuntu 9.1 with Python 2.6, but on Os X 10.5 with Python 2.5 the database filename is changed by the operating system by attaching the .db extension to it. Does an one know why is that? What is worse, at the time of reading it we get the error below the extracted code, on Os X 10.5: if os.path.exists( tarname )and tarfile.is_tarfile( tarname ): try: datastore_tarfile=tarfile.open( tarname, 'r:gz' ) print "Successfully opened the tarball: %s"%tarname members=datastore_tarfile.getnames() for dbmFile in members: datastore_tarfile.extract( dbmFile ) print "Extracting Realizations File: %s"%dbmFile realizations=shelve.open( dbmFile, 'c', 2, writeback = False ) Successfully opened the tarball: datastore.tar.gz Extracting Realizations File: realizations.dbm.db (22, 'Invalid argument') This does not happen on Windows XP with Python 2.5. Does anyone know what is happening on Os X? Any comments and suggestions will be greatly appreciated. Thank you very much in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: shelve.open generates (22, 'Invalid argument') Os X 10.5 with Python 2.5
On Feb 14, 1:21 pm, [email protected] (Aahz) wrote: > Nope -- any reason you can't change the filename? > -- Os X 10.5 did not recognized the dbm extension. But, I have been able to fix the problem (hope it helps somebody): At http://docs.python.org/library/shelve.html it says: "shelve.open(filename[, flag='c'[, protocol=None[, writeback=False]]])¶ Open a persistent dictionary. The filename specified is the base filename for the underlying database. As a side-effect, an extension may be added to the filename and more than one file may be created. By default, the underlying database file is opened for reading and writing. " Then, I went ahead and try to find out which type of db file was being created: print whichdb.whichdb(dbmFile)#prints bsddb185 kpfmac:xLPR kpf$ python Python 2.5.1 (r251:54863, Feb 9 2009, 18:49:36) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import bsddb185 >>> bsddb185.open('realizations.db') I found that the dbm extension is generated by bsddb and bsddb3 so I went ahead and installed it: sudo easy_install bsddb3. Finally, in our code, I just went ahead and instead of using shelve.open, I am calling shelve.BsdDbShelf(bsddb3.btopen(filename, 'c')) #realizations=shelve.open( filename, 'c', 2, writeback = False ) #hk 021010: need to use BsdDbShelf to ensure the usage of bsddb3 on OsX 10.5 #shelve.open creates a bsddb185 file on OsX 10.5 #but shelve.open on OsX reads with bsddb3, who knows why... #as a result the shelve.open throws # (22, 'Invalid argument') dbshelf=shelve.BsdDbShelf(bsddb3.btopen(filename, 'c')) realizations=dbshelf And that fixed on Os X 10.5. It also works fine on Windows, by ensuring the proper import: try: import bsddb3 except: import bsddb as bsddb3 -- http://mail.python.org/mailman/listinfo/python-list
Pyserial and pyQt
I have used pyserial in the past but this is my first experience with pyQt. I am using the Python xy package for windows current but might move to linux. I have a small device that is outputting a basic text string. I want to be able to read this string(from the comm port) and update a text box and eventually a graph in pyQt. I can't find any documentation or tutorials on how to do this. If anyone can point me in the right direction or give me some tips I would be grateful. Thanks, Seth -- http://mail.python.org/mailman/listinfo/python-list
Re: Pyserial and pyQt
On Jul 21, 7:24 pm, David Boddie wrote: > On Tuesday 21 July 2009 21:37, Seth wrote: > > > I have used pyserial in the past but this is my first experience with > > pyQt. I am using the Python xy package for windows current but might > > move to linux. I have a small device that is outputting a basic text > > string. I want to be able to read this string(from the comm port) and > > update a text box and eventually a graph in pyQt. I can't find any > > documentation or tutorials on how to do this. If anyone can point me > > in the right direction or give me some tips I would be grateful. > > It seems that someone has already asked a similar question on Stack > Overflow, though perhaps you should start with a simpler solution > and look at more advanced ones later: > > http://stackoverflow.com/questions/771988/pyqt4-and-pyserial > > One starting point is this list of tutorials on the PyQt and PyKDE Wiki: > > http://www.diotavelli.net/PyQtWiki/Tutorials > > Later, when you want to draw graphs, you might find PyQwt useful: > > http://pyqwt.sourceforge.net/ > > You may already be aware that there's also a mailing list for PyQt and > PyKDE: > > http://www.riverbankcomputing.com/pipermail/pyqt/ > > Another way to get answers to questions is to join the #pyqt IRC channel > at freenode.net: > > irc://irc.freenode.net/ > > David Thanks for the response. I have gone through a lot of the tutorials. All of them(that I saw) seem to just deal will event-based applications ie calculator, image viewer, etc. How do I run pyserial in the background and pass the information to PyQT and refresh the screen? Is there a way to have pyserial run in another thread and pass the information to the UI? Thanks, Seth -- http://mail.python.org/mailman/listinfo/python-list
Help with Asyncore
Hello, I am using Asyncore.dispatcher around a socket (well call the wrapped version a channel). This channel is passed around to other objects. These objects call "send" on the channel. My question is, what do you do for "writable" and "handle_write"? Those seemed designed for channel-internal buffers. Should I also overwrite "send" and have the data appended to a buffer? If not, how should writable and handle_write be implemented? I'm not sure what to do here... Thank you in advance, -- Seth Nielson -- http://mail.python.org/mailman/listinfo/python-list
Re: A replacement for lambda
I understand that there are a number of people who wish to remove lambda entirely from the language. Nevertheless, I find it a useful and powerful tool in actual development. Any replacement must support the following: *delayed evaluation*. I need a convenient (def is not always convenient) way of saying, "don't do this now". That is why I use lambda. -- Seth Nielson On 7/30/05, Reinhold Birkenfeld <[EMAIL PROTECTED]> wrote: > Stefan Rank wrote: > > on 30.07.2005 10:20 Paolino said the following: > >> why (x**2 with(x))<(x**3 with(x)) is not taken in consideration? > >> > >> If 'with' must be there (and substitue 'lambda:') then at least the > >> syntax is clear.IMO Ruby syntax is also clear. > >> > > > > I am sorry if this has already been proposed (I am sure it has). > > > > Why not substitue python-lambdas with degenerated generator expressions:: > > > >(lambda x: func(x)) == (func(x) for x) > > > > i.e. a one time callable generator expression (missing the `in` part). > > The arguments get passed into the generator, I am sure that can be > > combined with the PEP about passing args and Exceptions into a generator. > > It's hard to spot, and it's too different to a genexp to have such a similar > syntax. > > Reinhold > -- > http://mail.python.org/mailman/listinfo/python-list > -- http://mail.python.org/mailman/listinfo/python-list
gdbm dying wierdly
Hi guys. I'm using a python script as a redirector for Squid. My python script uses gdbm and exhibits some weird behavior. 1. If I run the script stand-alone, it loads the gdbm database file just fine. 2. If the script is launched from squid, when it tries to load the gdbm database, it dies WITHOUT an exception! It just disappears! (signal maybe?) Please help! I'm up against the wall! -- Seth N. -- http://mail.python.org/mailman/listinfo/python-list
Re: gdbm dying wierdly
Nevermind. The problem wasn't in gdbm. I had "exception" in stead of "Exception" in the try-except statement. -- SethNOn 8/27/05, Seth Nielson <[EMAIL PROTECTED]> wrote: Hi guys. I'm using a python script as a redirector for Squid. My python script uses gdbm and exhibits some weird behavior. 1. If I run the script stand-alone, it loads the gdbm database file just fine. 2. If the script is launched from squid, when it tries to load the gdbm database, it dies WITHOUT an exception! It just disappears! (signal maybe?) Please help! I'm up against the wall! -- Seth N. -- http://mail.python.org/mailman/listinfo/python-list
tarfile vs zipfile
Is there a reason tarfile and zipfile don't use the same method/member names, where it makes sense? Consider the following six methods/members, which I would expect to be the same (with the possible exception of mtime vs date_time, which are of different types). It almost seems like someone went out of their way to make it difficult to use them interchangeably. tarfile zipfile TarFile ZipFile getmember(name) getinfo(name) getmembers() infolist() getnames() namelist() TarInfo ZipInfo name filename mtimedate_time size file_size -- https://mail.python.org/mailman/listinfo/python-list
minidom and unicode errors
Hi all,I'm trying to parse and modify an XML document using xml.dom.minidom module and Python 2.4.2>> from xml.dom import minidom>> dom = minidom.parse ("c:/test.txt")If the xml file contains a non-ascii character, then i get a parse error.
I have the following line in my xml file:Exception beim Löschen des Audit-Moduls aufgetreten.
Exception Stack lautet: %1.ExpatError: not well-formed (invalid token): line 8, column 27If I remove the ö character, then it works fine. I'm guessing this has to do with the default encoding which is ascii. I guess i can change the encoding by modifying a file on my machine that the interpretter reads while loading, but then how do I get my program to work on different machines?
Also, while writing such a special character to the file, I get an error.>> document.writexml (file (myFile, "w"), encoding='utf-8')UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 16: ordinal not in range(128)
Any help would be appreciated.-- Regards,Abhimanyu
--
http://mail.python.org/mailman/listinfo/python-list
Re: minidom and unicode errors
On 3/7/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
Abhimanyu Seth wrote:> I'm trying to parse and modify an XML document using xml.dom.minidom module> and Python 2.4.2>> >> from xml.dom import minidom> >> dom = minidom.parse
("c:/test.txt")>> If the xml file contains a non-ascii character, then i get a parse error.> I have the following line in my xml file:> Exception beim Löschen des Audit-Moduls aufgetreten. Exception Stack
> lautet: %1.> ExpatError: not well-formed (invalid token): line 8, column 27>> If I remove the ö character, then it works fine. I'm guessing this has to do> with the default encoding which is ascii. I guess i can change the encoding
> by modifying a file on my machine that the interpretter reads while loading,> but then how do I get my program to work on different machines?the default encoding for XML is UTF-8. If you're using any other encoding
in your XML file, you have to specify that in the file itself, by putting an construct at the top of the file. e.g.
... rest of XML file follows ...> Also, while writing such a special character to the file, I get an error.> >> document.writexml (file (myFile, "w"), encoding='utf-8')>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position
> 16: ordinal not in range(128)not sure; maybe you've added byte strings (encoded strings instead of Unicodestrings) to the document, or maybe there's a bug in minidom. What happens ifyou remove the encoding argument? If you still get the same error after doing
that, make sure you use only Unicode strings when you add stuff to the document.hope this helps!--http://mail.python.org/mailman/listinfo/python-list
I've specified utf-8 in the xml headerIn writexml (), even without specifying the encoding, I get the same error. That't why I tried manually specifying the encoding.
But I managed to find a workaround.I got some clues from http://evanjones.ca/python-utf8.htmlAccording to the site,import codecsfileObj =
codecs.open( "someFile", "r", "utf-8" )u = fileObj.read() # Returns a Unicode string from the UTF-8 bytes in the fileshould return me a unicode string. But I still get an error.
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 407-410: invalid dataI can't figure out why! Why can't it parse ö character as unicode?Anyway, >> f = codecs.open ("c:/test.txt", "r", "latin-1")
>> dom = minidom.parseString (codecs.encode (f.read(), "utf-8"))works. But then I dunno if this will work for chinese or other unicode characters.How do I make my code read unicode files?
Also, while writing the xml file, I now use codecs.open ()>> document.writexml (codecs.open (mFile, "w", "utf-8"), encoding="utf-8")IMHO, writexml should be taking care of this, instead of me having to use codecs. I guess this is a bug.
-- Regards,Abhimanyu
--
http://mail.python.org/mailman/listinfo/python-list
Re: minidom and unicode errors
On 3/7/06, Abhimanyu Seth <[EMAIL PROTECTED]> wrote:
On 3/7/06, Fredrik Lundh <
[EMAIL PROTECTED]> wrote:
Abhimanyu Seth wrote:> I'm trying to parse and modify an XML document using xml.dom.minidom module> and Python 2.4.2>> >> from xml.dom import minidom> >> dom = minidom.parse
("c:/test.txt")>> If the xml file contains a non-ascii character, then i get a parse error.> I have the following line in my xml file:> Exception beim Löschen des Audit-Moduls aufgetreten. Exception Stack
> lautet: %1.> ExpatError: not well-formed (invalid token): line 8, column 27>> If I remove the ö character, then it works fine. I'm guessing this has to do> with the default encoding which is ascii. I guess i can change the encoding
> by modifying a file on my machine that the interpretter reads while loading,> but then how do I get my program to work on different machines?the default encoding for XML is UTF-8. If you're using any other encoding
in your XML file, you have to specify that in the file itself, by putting an construct at the top of the file. e.g.
... rest of XML file follows ...> Also, while writing such a special character to the file, I get an error.> >> document.writexml (file (myFile, "w"), encoding='utf-8')>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position
> 16: ordinal not in range(128)not sure; maybe you've added byte strings (encoded strings instead of Unicodestrings) to the document, or maybe there's a bug in minidom. What happens ifyou remove the encoding argument? If you still get the same error after doing
that, make sure you use only Unicode strings when you add stuff to the document.hope this helps!--
http://mail.python.org/mailman/listinfo/python-list
I've specified utf-8 in the xml headerIn writexml (), even without specifying the encoding, I get the same error. That't why I tried manually specifying the encoding.
But I managed to find a workaround.I got some clues from http://evanjones.ca/python-utf8.html
According to the site,import codecsfileObj = codecs.open( "someFile", "r", "utf-8" )u = fileObj.read() # Returns a Unicode string from the UTF-8 bytes in the file
should return me a unicode string. But I still get an error.
UnicodeDecodeError: 'utf8' codec can't decode bytes in position 407-410: invalid dataI can't figure out why! Why can't it parse ö character as unicode?Anyway, >> f = codecs.open ("c:/test.txt", "r", "latin-1")
>> dom = minidom.parseString (codecs.encode (f.read(), "utf-8"))works. But then I dunno if this will work for chinese or other unicode characters.How do I make my code read unicode files?
Also, while writing the xml file, I now use codecs.open ()>> document.writexml (codecs.open (mFile, "w", "utf-8"), encoding="utf-8")IMHO, writexml should be taking care of this, instead of me having to use codecs. I guess this is a bug.
-- Regards,Abhimanyu
Actually, it doesn't work. I don't get any errors, but it doesn't write the special characters. It's converted them to some gibberish.ö has become ö.Now I'm stumped!
-- Regards,Abhimanyu
--
http://mail.python.org/mailman/listinfo/python-list
Re: minidom and unicode errors
On 3/7/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
Abhimanyu Seth wrote:> > I have the following line in my xml file:> > Exception beim Löschen des Audit-Moduls aufgetreten. Exception> Stack> > lautet: %1.
> > ExpatError: not well-formed (invalid token): line 8, column 27> I've specified utf-8 in the xml header> are you sure you're using utf-8 in the XML file? the ö you pasted into
your mail is an iso-8859-1 code, not an utf-8 code.> Anyway,> >> f = codecs.open ("c:/test.txt", "r", "latin-1")> >> dom = minidom.parseString (codecs.encode
(f.read(), "utf-8"))> works.which means that you've labelled the file as utf-8, but that it actuallycontains iso-8859-1. fixing the file should fix this.
--http://mail.python.org/mailman/listinfo/python-listSorry, my mistake. The file was not saved as utf-8. Saving it as utf-8 solves my problems.
>> f = codecs.open ("c:/test.txt", "r", "utf-8")>> dom = minidom.parseString (codecs.encode (f.read(), "utf-8"))However, I still need to encode the string returned by
f.read () before passing it to parseString. Otherwise I get an exception.Thanks, anyway for all the help.-- Regards,Abhimanyu
--
http://mail.python.org/mailman/listinfo/python-list
Re: minidom and unicode errors
On 3/7/06, Fredrik Lundh <[EMAIL PROTECTED]> wrote:
Abhimanyu Seth wrote:> Sorry, my mistake. The file was not saved as utf-8. Saving it as utf-8> solves my problems.> >> f = codecs.open ("c:/test.txt", "r", "utf-8")
> >> dom = minidom.parseString (codecs.encode (f.read(), "utf-8"))>> However, I still need to encode the string returned by f.read () before> passing it to parseString. Otherwise I get an exception.
if the file contains UTF-8 data,dom = minidom.parse("c:/test.txt")should be exactly equivalent to your recoding solution. if it isn't, post acopy of the sample file.(if you've double-checked, and are 100% certain that it's not your editor
or your environment that's playing tricks with you, you can also report thisover here:http://sourceforge.net/tracker/?group_id=5470&atid=105470
)--http://mail.python.org/mailman/listinfo/python-listHey thanks! yup, minidom.parse
() works just fine.But for writexml(), I still need to use codecs.open("c:/test.txt", "w", "utf-8"). Is this a bug in writexml() ?-- Regards,Abhimanyu
--
http://mail.python.org/mailman/listinfo/python-list
Re: Performance: sets vs dicts.
On 08/29/10 14:43, Peter Otten wrote:
John Nagle wrote:
Is the "in" test faster for a dict or a set?
Is "frozenset" faster than "set"? Use case is
for things like applying "in" on a list of 500 or so words
while checking a large body of text.
As Arnaud suspects: no significant difference:
$ python dictperf.py
dict --> 0.210289001465
set --> 0.202902793884
frozenset --> 0.198950052261
$ cat dictperf.py
import random
import timeit
with open("/usr/share/dict/words") as instream:
words = [line.strip() for line in instream]
#random.seed(42)
sample = random.sample(words, 501)
n = sample.pop()
y = random.choice(sample)
d = dict.fromkeys(sample)
s = set(sample)
f = frozenset(sample)
for lookup in d, s, f:
print type(lookup).__name__, "-->", timeit.timeit(
"n in lookup; y in lookup",
"from __main__ import lookup, n, y")
Peter
What about lists versus tuples?
--
http://mail.python.org/mailman/listinfo/python-list
Re: accessing a text file
On 09/05/10 16:47, Baba wrote:
> level: beginner
>
> how can i access the contents of a text file in Python?
>
> i would like to compare a string (word) with the content of a text
> file (word_list). i want to see if word is in word_list. let's assume
> the TXT file is stored in the same directory as the PY file.
>
> def is_valid_word(word, word_list)
>
>
> thanks
> Baba
f = open('text.txt')
data = f.read()
# You may want to convert it to a list
data = data.split()
# Returns true if word is in data, false otherwise
word in data
--
http://mail.python.org/mailman/listinfo/python-list
Combinations or Permutations
I need to know how to generate a list of combinations/permutations (can't remember which it is). Say I have a list of variables: [a,b,c,d,...,x,y,z] I am curious if there is an optimized way to generate this: [[a,b],[a,c],[a,d],...,[x,z],[y,z]] I currently have an iteration that does this: #list.py from math import * list1=['a','b','c','d','e'] list2=[] length=len(list1) for it1 in range(0 ,length): for it2 in range(it1+1, length): list2.append([list1[it1],list1[it2]]) print list2 However, this is one of the slowest parts of my function (beaten only by variable instantiation). I posted this on another forum looking to see if there was a different method completely. They said that my method was about as simple as it could get, but I might be able to find out how to optimize my code here. Thanks in advance. -- http://mail.python.org/mailman/listinfo/python-list
Re: Combinations or Permutations
On Sep 20, 3:08 pm, Mark Lawrence wrote: > On 20/09/2010 21:54, Seth Leija wrote: > > > > > > > I need to know how to generate a list of combinations/permutations > > (can't remember which it is). Say I have a list of variables: > > > [a,b,c,d,...,x,y,z] > > > I am curious if there is an optimized way to generate this: > > > [[a,b],[a,c],[a,d],...,[x,z],[y,z]] > > > I currently have an iteration that does this: > > > #list.py > > > from math import * > > > list1=['a','b','c','d','e'] > > list2=[] > > length=len(list1) > > > for it1 in range(0 ,length): > > for it2 in range(it1+1, length): > > list2.append([list1[it1],list1[it2]]) > > > print list2 > > > However, this is one of the slowest parts of my function (beaten only > > by variable instantiation). I posted this on another forum looking to > > see if there was a different method completely. They said that my > > method was about as simple as it could get, but I might be able to > > find out how to optimize my code here. > > > Thanks in advance. > > Check the docs for the itertools module. > > Cheers. > > Mark Lawrence. That works! That made my function significantly faster! It's still slower than I would like it, but this is enough for now. Thank you so much! -- http://mail.python.org/mailman/listinfo/python-list
