array and strings in Python 3
Hello, This is my first post on python mailing list. I've working in code which must run on python 2 and python 3. I am using array.array as data buffers. I am stuck with the following code line, which works on Python 2, but not on Python 3.1.2: >>> import array >>> array.array('B', 'test') Traceback (most recent call last): File "", line 1, in TypeError: an integer is required According to Python 3 documentation (as far as I understood it), it should work. Again, no problem on Python 2. I've googled for people with similar problems, but got nothing. Does anyone have an idea what could I be doing wrong? Thanks in advance. -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil -- http://mail.python.org/mailman/listinfo/python-list
Re: array and strings in Python 3
> The `array` module's handling of strings changed as well. Reading the > Python 3 docs @ http://docs.python.org/dev/library/array.html , we > find (all emphases added): > class array.array(typecode[, initializer]) > [...] > If given a list or string, the initializer is passed to the new > array’s fromlist(), frombytes(), or **fromunicode()** method (see > below) to add initial items to the array. Otherwise, the iterable > initializer is passed to the extend() method. > [...] > array.fromunicode(s) > Extends this array with data from the given unicode string. The > array **must be a type 'u' array**; **otherwise a ValueError is > raised**. Use array.frombytes(unicodestring.encode(enc)) to append > Unicode data to an array of some other type. > Actually I was using the 3.1 docs as reference, as it is the stable one. After your comments, I dug a bit more in the documentation and in the code, and I figured out that for unicode strings, you must pass 'u' as the first constructor parameter. > Incidentally, if you ran 2to3 over your code and weren't warned about > this change in the array module, then that's probably a bug in 2to3 > which ought to be reported: http://bugs.python.org > I am not using 2to3 because I am not converting Python 2 code to Python 3, I am writing code that must run on Python 2 and Python 3. Thank you for your help :) -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil -- http://mail.python.org/mailman/listinfo/python-list
PyUSB 1.0.0 alpha 1 release
Dear all, PyUSB 1.0.0 alpha 1 is out. Since alpha 0, this version : - Standard control requests through usb.control module. - String descriptors through usb.util module. - Complete PyUSB 0.4 API emulation. - Working libusb 1.0 support under Windows. For details check the ReleaseNotes.txt and ChangeLog files. This version can be download through sourceforge: https://sourceforge.net/projects/pyusb/files/PyUSB%201.0/1.0.0-alpha-1/ For further information about PyUSB visit the project website: http://pyusb.sourceforge.net -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil -- http://mail.python.org/mailman/listinfo/python-list
PyPi question
Dear all, I am the PyUSB author and recently I was asked to update pyusb package in the PyPi. The point is that I am not the maintainer and don't know who is. Now I need to contact the current package maintainer but I could not find how to do so through PyPi (as maintainer's email does not show). Does anyone know how am I supposed to proceed (open a support request, maybe) ? Thanks in advance. -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil -- http://mail.python.org/mailman/listinfo/python-list
ctypes and cygwin
Hello, I was trying to use the libusb 1.0 with cygwin environments and noticed that this library uses stdcall calling convention, but ctypes does not have WinDLL object for cygwin. As far as I know, libusb builds with stdcall calling convention on cygwin by default. My question is if ctypes should have WinDLL in cygwin or cygwin, as a kind of emulation of Unix, considers everything to be cdecl and libusb guys should change their default build behavior in cygwin. Not sure if this is the right place to ask this question, but if ctypes guy(s) took out WinDLL from cygwin, I believe he (they) had a good reason to do so... -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil -- http://mail.python.org/mailman/listinfo/python-list
Re: Perl Hacker, Python Initiate
2011/2/2 Gary Chambers : > All, > > Given the following Perl script: > > #!/usr/bin/perl > > %dig = ( > solaris => "/usr/sbin/dig", > linux => "/usr/bin/dig", > darwin => "/usr/bin/dig" > ); > > $DIG = $dig{"$^O"}; > $DOMAIN = "example.com"; > $DNS = "ns.example.com"; > $DIGCMD = qq/$DIG \@$DNS $DOMAIN axfr/; > > open DIG, "$DIGCMD|" or die "$DIG: $!\n"; > while () { > next if (/^;/); # Skip any comments > # If we match a CNAME record, we have an alias to something. > # $1 = alias (CNAME), $2 = canonical hostname > if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*CNAME\s+(\S+)\.${DOMAIN}\.$/) { > # Push an alias (CNAME) onto an array indexed on canonical hostname > push(@{$cnames{$2}}, $1); > } > # Here's a standard A (canonical hostname) record > # $1 = canonical hostname, $2 = IPv4 address > if (/^(\S+)\.${DOMAIN}\.\s+\d+\s+IN\s*A\s+(\S+)$/) { > $ip{$1} = $2; > } > } > close DIG; > > # Format and display it like niscat hosts: > # canonicalHostname alias1 [alias2 aliasN] ipAddress > for $host (sort keys %ip) { > print "$host "; > if (defined(@{$cnames{$host}})) { > print join(' ', @{$cnames{$host}}); > print " "; > } > print "$ip{$host}\n"; > } > exit 0; > > Will someone please provide some insight on how to accomplish that task in > Python? I am unable to continually (i.e. it stops after displaying a single > line) loop through the output while testing for the matches on the two > regular expressions. Thank you. > > -- Gary Chambers > -- > http://mail.python.org/mailman/listinfo/python-list > As this is a python list, don't expect people understand Perl code (I don't know Perl, for example). But I understand, you call the /usr/bin/dig program and do some text processing on its ouput. Am I right? If so, you might want to give a look at re and subprocess modules. http://docs.python.org/py3k/howto/regex.html http://docs.python.org/py3k/library/re.html http://docs.python.org/py3k/library/subprocess.html -- Best Regards, Wander Lairson Costa LCoN - Laboratório de Computação Natural - Natural Computing Laboratory (http://www.mackenzie.com.br/lcon.html) Programa de Pós-Graduação em Engenharia Elétrica (PPGEE) Faculdade de Computação e Informática (FCI) Universidade Presbiteriana Mackenzie - SP - Brazil -- http://mail.python.org/mailman/listinfo/python-list