Re: How to get a package pip installable?

2012-04-15 Thread Fayaz Yusuf Khan
nbvf...@gmail.com wrote:

> (test)chris@amnesia:~$ pip install django-easydump
> Downloading/unpacking django-easydump
> Could not find any downloads that satisfy the requirement django-easydump
> No distributions at all found for django-easydump
> Storing complete log in /Users/chris/.pip/pip.log
Works fine here. Although fails with other build errors.
Downloading/unpacking django-easydump
  Downloading django-easydump-0.2.3.tar.gz
  Running setup.py egg_info for package django-easydump
Traceback (most recent call last):
  File "", line 14, in 
  File "/home/fayaz/Programming/build/django-easydump/setup.py", line 6, 
in 
version=open('VERSION').read(),
IOError: [Errno 2] No such file or directory: 'VERSION'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

  File "", line 14, in 

  File "/home/fayaz/Programming/build/django-easydump/setup.py", line 6, in 


version=open('VERSION').read(),

IOError: [Errno 2] No such file or directory: 'VERSION'


Command python setup.py egg_info failed with error code 1
Storing complete log in /home/fayaz/.pip/pip.log
 
-- 
Cloud developer and architect
Dexetra SS, Bangalore, India
fayaz.yusuf.khan_AT_gmail_DOT_com
fayaz_AT_dexetra_DOT_com
+91-9746-830-823


-- 
http://mail.python.org/mailman/listinfo/python-list


No such file or directory: 'c:\\windows\\temp\\test'

2012-04-15 Thread contro opinion
in my computer
C:\Python27>python
Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)]
on win
32
Type "help", "copyright", "credits" or "license" for more information.
1.
>>> f=open(r'c:\windows\temp\test','r')
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test'
2.
>>> f=open(r'c:\windows\temp\test.txt','r')
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test.txt'
3.
>>> f=open('c:\\windows\\temp\\test','r')
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test'
4.
>>> f=open('c:\\windows\\temp\\test.txt','r')
Traceback (most recent call last):
  File "", line 1, in 
IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test.txt'

would you mind telling me what's wrong ?
-- 
http://mail.python.org/mailman/listinfo/python-list


File traversing

2012-04-15 Thread Nibin V M
Hello,

First of all..I am very new to python with no background in development
area! :)

Ok, here is my problem.I have opened a file and I need to check each
line of that file. I have done it with a while loop.

res_own_file = open('/bah')
res_own_list = res_own_file.readline()
res_tot_list=[]
while res_own_list:
  res_own_list=res_own_list.strip()
  res_own_list=res_own_list.replace(' ', '')
  res_name=res_own_list.split(':')
  if res_name[1:2] not in res_tot_list:
res_tot_list.append(res_name[1:2])
  res_own_list = res_own_file.readline()

As you can see above, I am reading each line, cut a particular field and
sort a unique list from it...I have two questions here

1. If I have to check the file again from beginning, I can't do it without
closing and re-opening file since the file pointer is assigned to the EOF
of the opened file right? If so, is there any alliterative method to do it?
I don't wish to mess the script with multiple file open-close code!

2. If I print  res_name, it will display like ['one', 'two']. If I
print  res_name[0], it will display one ; but if I print  res_name[1] it
will display error out of index instead of two. From my code, when I use
res_name[1:2] it's displaying second filed. Why it is behaving like this?

Thanks in advance!

Regards

Nibin.

http://TechsWare.in
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Bryan
Steven D'Aprano wrote:
> Bryan wrote:
> > Python 3(K) likes to use the same '.py' file extension as its
> > incompatible predecessors,
>
> And so it should.

We disagree. Not surprising in a "gotcha's" thread.

> > and in some/many/most *nix implementations,
> > it likes to install in the same place.
>
> I won't speak for Unixes, but that is certainly not the case with Linux.
> Each Python version gets its own location:

Yes, that was just silly of me to write that. All I want is a new
general convention for the most-likely-to-work invocation that won't
break with the change: "#!/usr/bin/env python" for Python 2 versus,
for example, "#!/usr/bin/env python3". Of course that's not an issue
of where python is installed, just a recommended naming convention.

> I don't intent to be rude, but anyone who isn't a complete newbie to
> programming but is surprised to the point of "gotcha" by version
> compatibilities simply hasn't been paying attention.

My perspective is simply different from yours. I'm not the one who
installs python on most of the boxes where I work or play. There's
little consistency, so I love conventions that usually work. I'd like
to advocate for Python 3, but the default install on Windows
commandeers the '.py' extension and breaks stuff that currently works.

Here's a discussion of the issue from late 2008. Amusingly, one of the
arguments for not changing the file extension was that Python 2 would
be gone in a few years.
http://www.velocityreviews.com/forums/t647251-running-python-2-and-python-3-on-the-same-machine.html

-Bryan

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No such file or directory: 'c:\\windows\\temp\\test'

2012-04-15 Thread Almar Klein
> IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test.txt'
> would you mind telling me what's wrong ?
>

I think the file that you try to open does not exists :)

Please be more specific. What are you trying to achieve, and are you
absolutely sure that such a file exist?

  Almar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Chris Angelico
On Sun, Apr 15, 2012 at 7:23 PM, Bryan
 wrote:
> Yes, that was just silly of me to write that. All I want is a new
> general convention for the most-likely-to-work invocation that won't
> break with the change: "#!/usr/bin/env python" for Python 2 versus,
> for example, "#!/usr/bin/env python3". Of course that's not an issue
> of where python is installed, just a recommended naming convention.

That's what happens if you altinstall python3 already.

Separate point though. Forgive me if I'm being obtuse, but cannot you
with a shebang specify the path to the Python interpreter you want?

#!/usr/local/bin/python3.3

versus

#!/usr/local/bin/python2.7

Isn't that kinda the point of a shebang instead of a simple keyword?

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: File traversing

2012-04-15 Thread Chris Angelico
On Sun, Apr 15, 2012 at 7:15 PM, Nibin V M  wrote:
> res_own_file = open('/bah')
> res_own_list = res_own_file.readline()
> res_tot_list=[]
> while res_own_list:
>   res_own_list=res_own_list.strip()
>   res_own_list=res_own_list.replace(' ', '')
>   res_name=res_own_list.split(':')
>   if res_name[1:2] not in res_tot_list:
>     res_tot_list.append(res_name[1:2])
>   res_own_list = res_own_file.readline()

You can iterate over the file thus:

for res_own_list in res_own_file:
  # body of loop here

That saves you the trouble of making sure you do the next readline at
the bottom, too.

(You may also want to consider using the 'with' statement to guarantee
a timely closing of the file. Outside the scope of this mail though.)

> As you can see above, I am reading each line, cut a particular field and
> sort a unique list from it...I have two questions here
>
> 1. If I have to check the file again from beginning, I can't do it without
> closing and re-opening file since the file pointer is assigned to the EOF of
> the opened file right? If so, is there any alliterative method to do it? I
> don't wish to mess the script with multiple file open-close code!

You should be able to use res_own_file.seek(0) to do that. I haven't
tested your code, but that ought to work. If it fails, post code that
uses seek and the error message you get, and someone will doubtless
know what's wrong.

> 2. If I print  res_name, it will display like ['one', 'two']. If I
> print  res_name[0], it will display one ; but if I print  res_name[1] it
> will display error out of index instead of two. From my code, when I use
> res_name[1:2] it's displaying second filed. Why it is behaving like this?

My guess here is that at the end of the file, you get a blank line.
When you use [1:2] syntax, you get back an empty list if the indices
are out of bounds; but [1] will throw an error.

if res_name[1:2] not in res_tot_list:
res_tot_list.append(res_name[1:2])

I think this list is just to collect unique entries, yes? If so, a set
may be more to your liking. Check out:
http://docs.python.org/py3k/library/stdtypes.html#set

Hope that's of some value!

Chris Angelico
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: No such file or directory: 'c:\\windows\\temp\\test'

2012-04-15 Thread Chris Angelico
On Sun, Apr 15, 2012 at 7:13 PM, contro opinion  wrote:
> in my computer
> C:\Python27>python
> Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on
> win
> 32
> Type "help", "copyright", "credits" or "license" for more information.
> 1.
 f=open(r'c:\windows\temp\test','r')
> Traceback (most recent call last):
>   File "", line 1, in 
> IOError: [Errno 2] No such file or directory: 'c:\\windows\\temp\\test'
>
> would you mind telling me what's wrong ?

When you open a file with 'r' (to read from it), it has to exist. Try
opening it with 'w' first; that should create the file and let you
write() contents to it. Then close it, and try opening it with 'r'. It
should then work.

ChrisA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Naming future objects and their methods

2012-04-15 Thread Almar Klein
Hi Stefan,

What do you think would be a "natural" way to name the
> future returned by `put_bytes` and possibly the `was_sent`
> method attached to it? Can you even come up with nice naming
> rules for futures and their methods? :-)
>

I think the intended way to get notified when a future is done is to
register a callback using future.add_done_callback(). If you want to
wait for the result value, you should use the future.result(timeout) method.

As for how to name the future object, what about simply "future"?

See also:
http://docs.python.org/dev/library/concurrent.futures.html#future-objects

Regards,
  Almar
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Mark Lawrence

On 15/04/2012 10:23, Bryan wrote:


My perspective is simply different from yours. I'm not the one who
installs python on most of the boxes where I work or play. There's
little consistency, so I love conventions that usually work. I'd like
to advocate for Python 3, but the default install on Windows
commandeers the '.py' extension and breaks stuff that currently works.



PEP397 discusses this issue, a solution is already available which works 
a treat.



-Bryan



--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-15 Thread Seymour J.
In <87aa2iz3l1@kuiper.lan.informatimago.com>, on 04/11/2012
   at 05:32 PM, "Pascal J. Bourguignon"  said:

>You're confused. C doesn't have arrays.  Lisp has arrays. C only has
>vectors

Neither C nor any other programming language has vectors ;-)

>That C calls its vectors "array", or its bytes "char" doesn't change
>the fact that C has no array and no character.

That various programming languages use the term "vector" for data
structures that are not vectors does not change the fact that they
don't have vectors.

If you're going to complain about C nomenclature, you'd have a much
better case complaining about "cast".

-- 
Shmuel (Seymour J.) Metz, SysProg and JOAT  

Unsolicited bulk E-mail subject to legal action.  I reserve the
right to publicly post or ridicule any abusive E-mail.  Reply to
domain Patriot dot net user shmuel+news to contact me.  Do not
reply to spamt...@library.lspace.org

-- 
http://mail.python.org/mailman/listinfo/python-list


Whither paramiko?

2012-04-15 Thread Bryan
Paramiko is a Python library for SSH (Secure Shell). Over about the
last year, I've grown dependent upon it. Its home page is still easy
to search up, but the links to its mailing list and repository don't
work.

Paramiko depends on PyCrypto, and not so long ago that dependency was
the stated reason why paramiko did not yet play with Python 3. Even
more recently, PyCrypto has gone green on the Python 3 Wall of Shame.

Anyone know recent news on the status of paramiko?

Thanks,
-Bryan
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Naming future objects and their methods

2012-04-15 Thread Michael Torrie
On 04/14/2012 04:22 PM, Stefan Schwarzer wrote:
> However, I'm not comfortable with the combination of the
> names of the future and its method. After all, not the
> `put_result` was sent, but the data that was the argument in
> the `put_bytes` call. Maybe `data_was_sent` is better than
> `was_sent`, but `put_result.data_was_sent()` doesn't feel
> right either.
> 
> What do you think would be a "natural" way to name the
> future returned by `put_bytes` and possibly the `was_sent`
> method attached to it? Can you even come up with nice naming
> rules for futures and their methods? :-)
> 
> I tried to find suggestions by using a search engine and
> StackOverflow, but wasn't successful. PEP 3148 [3] describes
> an API, but it's quite abstract (`Executor.submit`,
> `Future.result` etc.).

You might look at the Python Twisted asynchronous library for ideas.
-- 
http://mail.python.org/mailman/listinfo/python-list


Writing Android application using GPS data with Python

2012-04-15 Thread Noam Peled
I want to write an Android application using Python. I've found 2 options for 
that: kivy and SL4A. In kivy, at least for now, I can't use the GPS data. 
Anyone knows if I can get the GPS data using SL4A with Python? As I understood, 
one can write commercial apps using kivy. On the other hand, with SL4A you must 
install first SL4A and python on your Android device, so I'm not sure it's 
suitable for commercial apps. And last one, can I use funf with python?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Steven D'Aprano
On Sun, 15 Apr 2012 02:23:27 -0700, Bryan wrote:

> Steven D'Aprano wrote:
>> Bryan wrote:
>> > Python 3(K) likes to use the same '.py' file extension as its
>> > incompatible predecessors,
>>
>> And so it should.
> 
> We disagree. Not surprising in a "gotcha's" thread.

Yes, but I have reasons for disagreeing, which you trimmed out of your 
response. If you have reasons for thinking that a separate file extension 
for Python 3 is a good idea, you are keeping it to yourself.

Python and C are different languages. Python 2 and Python 3 are not, they 
are the same language with only a few minor dialect differences.

There is a practical argument against separate file extensions: which 
extension do you use for code intended to run with both Python 2 and 3?

We didn't need a new file extension for the transition between Python 2.5 
(string exceptions are legal) and Python 2.6 (string exceptions cause a 
SyntaxError exception). Nor did we need a new file extension for the 
transition between Python 2.1 (nested functions behaved one way) and 
Python 2.2 (nested functions behaved a different way). We certainly 
didn't have a new file extension when the bastion or gopher modules were 
removed from the standard library, backwards-incompatible changes if I've 
ever seen one.

If there's a good argument in favour of separate file extensions for 
Python 2 and Python 3 (one which doesn't also apply to, say, Python 2.5 
and 2.6, or 3.1 and 3.2) I'm afraid I don't know it.


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Curt
On 2012-04-15, Steven D'Aprano  wrote:
>> 
>> We disagree. Not surprising in a "gotcha's" thread.
>
> Yes, but I have reasons for disagreeing, which you trimmed out of your 
> response. If you have reasons for thinking that a separate file extension 
> for Python 3 is a good idea, you are keeping it to yourself.

Didn't you trim his reasons, speaking of trimming (maybe they were
nonsensical, or poor, but it seems they were there before you made them
disappear)?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Writing Android application using GPS data with Python

2012-04-15 Thread Boris FELD
You can try appaccelerator, it seems to support python and you should be
able to access geolocalisation (according to wikipedia:
https://en.wikipedia.org/wiki/Appcelerator_Titanium)

Le 15 avril 2012 16:44, Noam Peled  a écrit :

> I want to write an Android application using Python. I've found 2 options
> for that: kivy and SL4A. In kivy, at least for now, I can't use the GPS
> data. Anyone knows if I can get the GPS data using SL4A with Python? As I
> understood, one can write commercial apps using kivy. On the other hand,
> with SL4A you must install first SL4A and python on your Android device, so
> I'm not sure it's suitable for commercial apps. And last one, can I use
> funf with python?
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-15 Thread Ian Kelly
On Sat, Apr 14, 2012 at 8:57 PM, Shmuel  Metz
 wrote:
> In <87aa2iz3l1@kuiper.lan.informatimago.com>, on 04/11/2012
>   at 05:32 PM, "Pascal J. Bourguignon"  said:
>
>>You're confused. C doesn't have arrays.  Lisp has arrays. C only has
>>vectors
>
> Neither C nor any other programming language has vectors ;-)

AFAIK, C++ nomenclature notwithstanding, a vector is just an array
with only one or indices, so all languages that have arrays have
vectors.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie python questions...

2012-04-15 Thread rusi
On Apr 15, 7:47 am, Steven D'Aprano  wrote:
> On Sat, 14 Apr 2012 11:25:57 -0700, vmars316 wrote:
> > win7HomePremium:
> > Greetings,
> > 1)
> > I installed portablePython(pP) here:
> > C:\Users\vmars\Python3
> >  ?Does that look ok?
>
> Sure, why not?
>
> > 2)
> > I would like to try pyWin, but it won't let me install because there is
> > no pP3.2 in registry.
> >  ? How can I update the Registry for Python3.2 ?
>
> I'm not a Windows expert, but isn't one of the points of Portal Python
> that it doesn't mess with the registry?
>
> If you don't get an answer here after a couple of days, perhaps try
> asking again on a Portable Python or pyWin mailing list.
>
> > 3) When ever I cllick on *.py file,
> > it runs by so fast that I can't see what's going on.
> >  ?Is there a way to keep the pyconsole open 'til i decide to close
> > it?
>
> Put this line at the very end of your script:
>
> x = input("Press Enter to continue... ")
>
> > 4)
> > I can't seem to get turtleDemo running. ?Can anyone step me thru this?

Ive had issues with turtle in windows which were not on linux
http://mail.python.org/pipermail/python-list/2011-May/1272708.html
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Newbie python questions...

2012-04-15 Thread rusi
On Apr 14, 11:25 pm, vmars316  wrote:
> win7HomePremium:
> Greetings,
> 1)
> I installed portablePython(pP) here:
> C:\Users\vmars\Python3
>  ?Does that look ok?

A brief look at portable python's website indicates that its meant for
running off usb sticks (ie without installation)
If you are installing in the normal way, why not use normal python?

http://www.python.org/getit/

[First time I'm hearing of portable python]
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Naming future objects and their methods

2012-04-15 Thread Laurent Pointal
Stefan Schwarzer wrote:

> Hello,
> 
> I wrote a `Connection` class that can be found at [1]. A
> `Connection` object has a method `put_bytes(data)` which
> returns a "future" [2]. The data will be sent asynchronously
> by a thread attached to the connection object.
> 
> The future object returned by `put_bytes` has a `was_sent`
> method which will return `True` once the sender thread has
> actually sent the data via a socket call. An example might
> look like
> 
> put_result = connection.put_bytes(data)
> if put_result.was_sent(timeout=1.0):
> print "Data has been sent."
> else:
> print "Data hasn't been sent within one second."
> 
> However, I'm not comfortable with the combination of the
> names of the future and its method. After all, not the
> `put_result` was sent, but the data that was the argument in
> the `put_bytes` call. Maybe `data_was_sent` is better than
> `was_sent`, but `put_result.data_was_sent()` doesn't feel
> right either.


Just an idea:
put_result ==> dataput
was_sent ==> sent

dataput = connection.put_bytes(data)
if dataput.sent(timeout=1.0):
print "Data has been sent."
else:
print "Data hasn't been sent within one second."


-- 
Laurent POINTAL - laurent.poin...@laposte.net
3 allée des Orangers - 91940 Les Ulis - France
Tél. 01 69 29 06 59

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Steven D'Aprano
On Sun, 15 Apr 2012 15:30:39 +, Curt wrote:

> On 2012-04-15, Steven D'Aprano 
> wrote:
>>> 
>>> We disagree. Not surprising in a "gotcha's" thread.
>>
>> Yes, but I have reasons for disagreeing, which you trimmed out of your
>> response. If you have reasons for thinking that a separate file
>> extension for Python 3 is a good idea, you are keeping it to yourself.
> 
> Didn't you trim his reasons, speaking of trimming (maybe they were
> nonsensical, or poor, but it seems they were there before you made them
> disappear)?

No, you remember wrongly. Bryan states that the use of the same file 
extension is a gotcha, but that's it.

[quote]
Python 3(K) likes to use the same '.py' file extension as 
its incompatible predecessors

http://mail.python.org/pipermail/python-list/2012-April/1290909.html


Python 3 uses the same file extension as its incompatible predecessors 
for the same reason that Python 2.6 uses the same file extension as its 
incompatible predecessors, and 2.5 as as its incompatible predecessors, 
and so on all the way back.

"Incompatible" is not a binary state, it is a matter of degree. Python 
3.1 is less compatible to Python 2.7 than 2.7 is to 2.6, but the vast 
bulk of the language is still identical and code supporting everything 
from 2.5 to 3.2 in one code base is possible.

In my experience, it is MUCH easier to write code targeting versions 2.5 
through 3.2 than it is to target 2.4 and 2.5 only, on account of how 
impoverished 2.4 is compared to 2.5. (I once started a project to 
backport useful 2.5 features to 2.4. I gave up because it was just too 
painful.)


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Bryan
Steven wrote:
> Yes, but I have reasons for disagreeing, which you trimmed out of your
> response. If you have reasons for thinking that a separate file extension
> for Python 3 is a good idea, you are keeping it to yourself.

On Windows the file extension determines what executable opens the
file. Running both Python 2 and Python 3 on Windows is painful where
it doesn't need to be. I'd like to encourage my users to check out
Python 3, but installing it on Windows will take over the '.py'
extension and break stuff that currently works.

Incidentally, I'm not actually advocating for '.py3'. I'm advocating
for '.py4'.

> Python and C are different languages. Python 2 and Python 3 are not, they
> are the same language with only a few minor dialect differences.

You could think of it as the same file extension in a different
dialect, but really the works/broken distinction is more important
than language/dialect.

> There is a practical argument against separate file extensions: which
> extension do you use for code intended to run with both Python 2 and 3?

The file extension default should work with the the recommended
transition method, which is not dual-major-version code. Admittedly,
support for such code has improved.

> We didn't need a new file extension for the transition between Python 2.5
> (string exceptions are legal) and Python 2.6 (string exceptions cause a
> SyntaxError exception). Nor did we need a new file extension for the
> transition between Python 2.1 (nested functions behaved one way) and
> Python 2.2 (nested functions behaved a different way). We certainly
> didn't have a new file extension when the bastion or gopher modules were
> removed from the standard library, backwards-incompatible changes if I've
> ever seen one.

Python's management of backwards compatibility for minor version has
worked pretty well, at least for me. Major version simply do not
attempt backward compatibility.

Your experience seems to be quite different from mine. I don't recall
a minor version upgrade ever giving me significant trouble with my own
code. The issue has been the external libraries upon which I depend,
and they've tended to catch up quickly, unlike what we're seeing with
Python 3.

> If there's a good argument in favour of separate file extensions for
> Python 2 and Python 3 (one which doesn't also apply to, say, Python 2.5
> and 2.6, or 3.1 and 3.2) I'm afraid I don't know it.

Because it would allow Windows user to play with Python 3 alongside
Python 2, while waiting for external libraries to catch up. Of course
they can, as I am, but the gotchas are really annoying. With minor
versions its not a big deal if most users simply wait to do an
upgrade.

-Bryan
-- 
http://mail.python.org/mailman/listinfo/python-list


escaping

2012-04-15 Thread Kiuhnm

This is the behavior I need:
path = path.replace('\\', '')
msg = ". {} .. '{}' .. {} .".format(a, path, b)
Is there a better way?

Kiuhnm
--
http://mail.python.org/mailman/listinfo/python-list


Re: escaping

2012-04-15 Thread Steve Howell
On Apr 15, 2:07 pm, Kiuhnm  wrote:
> This is the behavior I need:
>      path = path.replace('\\', '')
>      msg = ". {} .. '{}' .. {} .".format(a, path, b)
> Is there a better way?
>

A little more context would help.  The quadruple-toothpick idiom
predates Python.  It's a little hard on the fingers and eyes at first,
but it's pretty expressive--most people will clearly see that you are
dealing with escaping issues.

If you are just printing a message to the log, consider repr().
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Naming future objects and their methods

2012-04-15 Thread Cameron Simpson
On 15Apr2012 00:22, Stefan Schwarzer  wrote:
| I wrote a `Connection` class that can be found at [1]. A
| `Connection` object has a method `put_bytes(data)` which
| returns a "future" [2]. The data will be sent asynchronously
| by a thread attached to the connection object.
[...]
| put_result = connection.put_bytes(data)
| if put_result.was_sent(timeout=1.0):
| print "Data has been sent."
| else:
| print "Data hasn't been sent within one second."
| 
| However, I'm not comfortable with the combination of the
| names of the future and its method. After all, not the
| `put_result` was sent, but the data that was the argument in
| the `put_bytes` call. Maybe `data_was_sent` is better than
| `was_sent`, but `put_result.data_was_sent()` doesn't feel
| right either.
| 
| What do you think would be a "natural" way to name the
| future returned by `put_bytes` and possibly the `was_sent`
| method attached to it? Can you even come up with nice naming
| rules for futures and their methods? :-)

I'd call it "packet", and was_sent just "sent".

  if packet.sent(timeout=1.0):

Cheers,
-- 
Cameron Simpson  DoD#743
http://www.cskk.ezoshosting.com/cs/

If you 'aint falling off, you ar'nt going hard enough.  - Fred Gassit
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escaping

2012-04-15 Thread Terry Reedy

On 4/15/2012 5:07 PM, Kiuhnm wrote:

This is the behavior I need:
path = path.replace('\\', '')
Is there a better way?


For one-time use, and given that you cannot un-double with the r prefix, 
not that I know of. For using the substrings multiple times, name them.


>>> s = r'abc\cd\ef'
>>> bs = '\\'
>>> bs2 = bs+bs
>>> s.replace(bs, bs2)
'abccdef'
>>> len(s.replace(bs, bs2))
11
# and continue to use bs and bs2

--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-15 Thread Terry Reedy

On 4/15/2012 12:16 PM, Ian Kelly wrote:

On Sat, Apr 14, 2012 at 8:57 PM, Shmuel  Metz
  wrote:

In<87aa2iz3l1@kuiper.lan.informatimago.com>, on 04/11/2012
   at 05:32 PM, "Pascal J. Bourguignon"  said:


You're confused. C doesn't have arrays.  Lisp has arrays. C only has
vectors


Neither C nor any other programming language has vectors ;-)


AFAIK, C++ nomenclature notwithstanding, a vector is just an array
with only one or indices, so all languages that have arrays have
vectors.


Vectors are magnitude with direction, often represented by 1-d array of 
projections on coordinate axes. If a = 1,2,3 and b = 3,2,1 are 
(mathematical) vectors, then a+b = 4,4,4; 2*a = 2,4,6; and a*b = (3+4+3) 
= 10.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: No such file or directory: 'c:\\windows\\temp\\test'

2012-04-15 Thread Terry Reedy

On 4/15/2012 5:13 AM, contro opinion wrote:


 >>> f=open(r'c:\windows\temp\test','r')



 >>> f=open('c:\\windows\\temp\\test','r')


Your life will be much happier is you use forward slashes for filenames 
in Python programs.

f = open('c:/windows/temp/test', 'r')

You only need backslashes when entering filenames in Command Prompt 
window that Command Prompt must interpret as a path.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-15 Thread Ian Kelly
On Sun, Apr 15, 2012 at 4:49 PM, Terry Reedy  wrote:
> On 4/15/2012 12:16 PM, Ian Kelly wrote:
>>
>> On Sat, Apr 14, 2012 at 8:57 PM, Shmuel  Metz
>>   wrote:
>>>
>>> In<87aa2iz3l1@kuiper.lan.informatimago.com>, on 04/11/2012
>>>   at 05:32 PM, "Pascal J. Bourguignon"  said:
>>>
 You're confused. C doesn't have arrays.  Lisp has arrays. C only has
 vectors
>>>
>>>
>>> Neither C nor any other programming language has vectors ;-)
>>
>>
>> AFAIK, C++ nomenclature notwithstanding, a vector is just an array
>> with only one or indices, so all languages that have arrays have
>> vectors.
>
>
> Vectors are magnitude with direction, often represented by 1-d array of
> projections on coordinate axes. If a = 1,2,3 and b = 3,2,1 are
> (mathematical) vectors, then a+b = 4,4,4; 2*a = 2,4,6; and a*b = (3+4+3) =
> 10.

I'm referring to the programming usage, not the mathematical usage.
See definition #4 at dictionary.com, or definition #8 at wiktionary.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Terry Reedy

On 4/15/2012 4:01 PM, Bryan wrote:


On Windows the file extension determines what executable opens the
file. Running both Python 2 and Python 3 on Windows is painful where
it doesn't need to be. I'd like to encourage my users to check out
Python 3, but installing it on Windows will take over the '.py'
extension and break stuff that currently works.


There used to be an option to not do that, but it seems to have either 
be removed or hidden. I admit that telling people to re-install 2.7 (or 
whatever), just to recapture the file extension, is a nuisance. The new 
PEP397 runner seems to be a better solution.



The file extension default should work with the the recommended
transition method,


There is no single recommended transition method at present.


which is not dual-major-version code.


The acceptance of irrelevant 'u' prefixes for strings in 3.3 is de facto 
acceptance of that as *one* recommended method.


--
Terry Jan Reedy

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Mark Lawrence

On 15/04/2012 21:01, Bryan wrote:

Steven wrote:

Yes, but I have reasons for disagreeing, which you trimmed out of your
response. If you have reasons for thinking that a separate file extension
for Python 3 is a good idea, you are keeping it to yourself.


On Windows the file extension determines what executable opens the
file. Running both Python 2 and Python 3 on Windows is painful where
it doesn't need to be. I'd like to encourage my users to check out
Python 3, but installing it on Windows will take over the '.py'
extension and break stuff that currently works.

Incidentally, I'm not actually advocating for '.py3'. I'm advocating
for '.py4'.


Python and C are different languages. Python 2 and Python 3 are not, they
are the same language with only a few minor dialect differences.


You could think of it as the same file extension in a different
dialect, but really the works/broken distinction is more important
than language/dialect.


There is a practical argument against separate file extensions: which
extension do you use for code intended to run with both Python 2 and 3?


The file extension default should work with the the recommended
transition method, which is not dual-major-version code. Admittedly,
support for such code has improved.


We didn't need a new file extension for the transition between Python 2.5
(string exceptions are legal) and Python 2.6 (string exceptions cause a
SyntaxError exception). Nor did we need a new file extension for the
transition between Python 2.1 (nested functions behaved one way) and
Python 2.2 (nested functions behaved a different way). We certainly
didn't have a new file extension when the bastion or gopher modules were
removed from the standard library, backwards-incompatible changes if I've
ever seen one.


Python's management of backwards compatibility for minor version has
worked pretty well, at least for me. Major version simply do not
attempt backward compatibility.

Your experience seems to be quite different from mine. I don't recall
a minor version upgrade ever giving me significant trouble with my own
code. The issue has been the external libraries upon which I depend,
and they've tended to catch up quickly, unlike what we're seeing with
Python 3.


If there's a good argument in favour of separate file extensions for
Python 2 and Python 3 (one which doesn't also apply to, say, Python 2.5
and 2.6, or 3.1 and 3.2) I'm afraid I don't know it.


Because it would allow Windows user to play with Python 3 alongside
Python 2, while waiting for external libraries to catch up. Of course
they can, as I am, but the gotchas are really annoying. With minor
versions its not a big deal if most users simply wait to do an
upgrade.

-Bryan


You can as I've already said do this but apparently you're more than 
happy to ignore solutions that have been given to you.  The 
implementation of PEP397 refers.  What more do you want?


--
Cheers.

Mark Lawrence.

--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread David Robinow
On Sun, Apr 15, 2012 at 4:01 PM, Bryan
 wrote:
> On Windows the file extension determines what executable opens the
> file. Running both Python 2 and Python 3 on Windows is painful where
> it doesn't need to be. I'd like to encourage my users to check out
> Python 3, but installing it on Windows will take over the '.py'
> extension and break stuff that currently works.

Hire a qualified Windows specialist.
Tell him to type:
   FTYPE Python.File="C:\Python27\python.exe" :%1: %*
Pay him $200.00
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: f python?

2012-04-15 Thread Terry Reedy


On 4/15/2012 6:59 PM, Ian Kelly wrote:

On Sun, Apr 15, 2012 at 4:49 PM, Terry Reedy  wrote:

On 4/15/2012 12:16 PM, Ian Kelly wrote:


On Sat, Apr 14, 2012 at 8:57 PM, Shmuel  Metz
wrote:


In<87aa2iz3l1@kuiper.lan.informatimago.com>, on 04/11/2012
   at 05:32 PM, "Pascal J. Bourguignon"said:


You're confused. C doesn't have arrays.  Lisp has arrays. C only has
vectors


According to the authors of C, the C standard committee, and probably 
hundreds of C authors, C has 'arrays', not 'vectors'. Fortran also has 
'arrays', with some systems having hardware or software extensions for 
vector (and matrix) processing (where vectors have the operations I 
specify below and matrixes have *their* operations).

(See for instance https://en.wikipedia.org/wiki/Fortran )


Neither C nor any other programming language has vectors ;-)


Generally not as a built-in type, though vector functions that treat 1-d 
arrays as vectors are common. So are added matrix classes and functions.



AFAIK, C++ nomenclature notwithstanding, a vector is just an array
with only one or indices, so all languages that have arrays have
vectors.


Confusing representation with concept is not very helpful. In biology, a 
vector is something that carries something from here to there. That is 
related to the astronomical/geometric/mathematical meaning.



Vectors are magnitude with direction, often represented by 1-d array of
projections on coordinate axes. If a = 1,2,3 and b = 3,2,1 are
(mathematical) vectors, then a+b = 4,4,4; 2*a = 2,4,6; and a*b = (3+4+3) =
10.



I'm referring to the programming usage, not the mathematical usage.
See definition #4 at dictionary.com, or definition #8 at wiktionary.


But you will not find that meaning in
http://www.merriam-webster.com/dictionary/vector

The mathematical usage *is* the programming usage in many programming 
languages and communities -- including Python. CPython lists are 
implemented as C arrays.


===
Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Andrew Berg
On 4/15/2012 3:01 PM, Bryan wrote:
> I'd like to encourage my users to check out
> Python 3, but installing it on Windows will take over the '.py'
> extension and break stuff that currently works.
Have you tried telling your users to tell the installer not to do that?
IIRC, it's a simple checkbox option. I have a 64-bit 3.2 as my main, but
I also have a 64-bit 3.3, a 32-bit 3.2 and a 32-bit 2.7 installed, and
not once did any of the installers hijack the association.

On 4/15/2012 6:24 PM, Terry Reedy wrote:
> There used to be an option to not do that, but it seems to have either
> be removed or hidden.
Perhaps it only appears for "custom installations" (or whatever it's
called). I had no problem installing 3.3a1 and upgrading it to 3.3a2
while keeping 3.2.x as the default.

-- 
CPython 3.2.3 | Windows NT 6.1.7601.17990
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: escaping

2012-04-15 Thread Steven D'Aprano
On Sun, 15 Apr 2012 23:07:36 +0200, Kiuhnm wrote:

> This is the behavior I need:
>  path = path.replace('\\', '')
>  msg = ". {} .. '{}' .. {} .".format(a, path, b)
> Is there a better way?


This works for me:

>>> a = "spam"
>>> b = "ham"
>>> path = r"C:\a\b\c\d\e.txt"
>>> msg = ". %s .. %r .. %s ." % (a, path, b)
>>> print msg
. spam .. 'C:\\a\\b\\c\\d\\e.txt' .. ham .



Another possibility:

>>> print path.encode('string_escape')
C:\\a\\b\\c\\d\\e.txt


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


How to execute/run a *.py file, win7, py3.2..?

2012-04-15 Thread vmars316
Greetings,
windows7, portablePython3.2:
What if i wanted to send myProg.py to a friend to RUN (who has python
installed).
Isn't there a way just to doubleClick on myProg.py, to get it into the
interpret/RUN?
Could i RUN a myProg.o ?
There must be a way to initiate the RUNning of a myProg.py without
IDLE or pyScript, or the like.
What if i wanted to write my own program in maybe "C",
who's job it is to initiate interpret/run any *.py program.
How does IDLE or pyScript do it?
And yes. i am interested in py2exe or the like, for windows7.
And would like to know what's available, like py2exe.

Thanks...vm
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute/run a *.py file, win7, py3.2..?

2012-04-15 Thread Andrew Berg
On 4/15/2012 11:30 PM, vmars316 wrote:
> Isn't there a way just to doubleClick on myProg.py, to get it into the
> interpret/RUN?
Use the standard installer from python.org if you want to do things with
the registry. The standard installer sets up the registry for you so
that the interpreter will be associated with *.py/*.pyw files.
If you tell us why you are using Portable Python, we can help you
accomplish whatever it is you're trying to accomplish with it. Much of
what you seem to want to do defeats the purpose of Portable Python.

-- 
CPython 3.2.2 | Windows NT 6.1.7601.17640
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute/run a *.py file, win7, py3.2..?

2012-04-15 Thread Dave Angel
On 04/16/2012 12:30 AM, vmars316 wrote:
> Greetings,
> windows7, portablePython3.2:
> What if i wanted to send myProg.py to a friend to RUN (who has python
> installed).
> Isn't there a way just to doubleClick on myProg.py, to get it into the
> interpret/RUN?
> Could i RUN a myProg.o ?
> There must be a way to initiate the RUNning of a myProg.py without
> IDLE or pyScript, or the like.
> What if i wanted to write my own program in maybe "C",
> who's job it is to initiate interpret/run any *.py program.
> How does IDLE or pyScript do it?
> And yes. i am interested in py2exe or the like, for windows7.
> And would like to know what's available, like py2exe.
>
> Thanks...vm

There's lots you don't say.  So I'll make some wild assumptions.

Your friend has Python 3.2 installed.  (not portable python)  She's
running Windows 7.  If she took the defaults, she should have the .py
extension associated with c:\somewhere\python27\python.exe

So yes, she can double-click on myProg.py in an explorer window. 
However, if there's any console output you want her to see, or if you
might have an error or two, it'd be convenient to do one of two things;

1) end the program with an input("Press Enter key to exit the script")
2) run it from a cmd prompt (Dos box).

She certainly doesn't need IDLE or pyScript;  I never use either of
them.  I do use Komodo IDE, but that's for debugging, not for running
the script.

myProg.o  is a Unix/Linux convention for an object file;  compiled but
not linked.  On Windows, that would be .obj.  And CPython does not
compile the code into a .obj,  It does compile modules into .pyc, but
that's no help for your question.

You can certainly write a C program, if you've bought a C compiler.  But
this is a Python forum.

Sorry, I have no experience with py2exe or the like.


-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


sort by column a csv file case insensitive

2012-04-15 Thread Lee Chaplin
Hi all,

I am trying to sort, in place, by column, a csv file AND sort it case
insensitive.
I was trying something like this, with no success:

import csv
import operator

def sortcsvbyfield(csvfilename, columnnumber):
  with open(csvfilename, 'rb') as f:
readit = csv.reader(f)
thedata = list(readit)

  thedata = sorted(thedata, key = lambda x:
(operator.itemgetter(columnnumber) ,x[0].lower()))  #!!!
  with open(csvfilename, 'wb') as f:
writeit = csv.writer(f)
writeit.writerows(thedata)

The line marked is the culprit.
Any help is greatly appreciated.

Thanks,
Lee
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sort by column a csv file case insensitive

2012-04-15 Thread Dave Angel
On 04/16/2012 01:11 AM, Lee Chaplin wrote:
> Hi all,
>
> I am trying to sort, in place, by column, a csv file AND sort it case
> insensitive.
> I was trying something like this, with no success:

Could you perhaps qualify that "no success" bit?  Do you mean it didn't
output a file, or that the file wasn't sorted right, or that the data
wasn't in the file at all, or that you got an exception, or that you got
a syntax error, or that your disk filled up, or what?  Please paste the
results of running it, along with a brief description of why that was
not a success.

It might also be useful to state your working environment, like you're
running 32 bit CPython version 1.7 on Windows 2009, or whatever.  in
this case, I don't think it matters, but somebody else may know differently.

> import csv
> import operator
>
> def sortcsvbyfield(csvfilename, columnnumber):
>   with open(csvfilename, 'rb') as f:
> readit = csv.reader(f)
> thedata = list(readit)
>
>   thedata = sorted(thedata, key = lambda x:
> (operator.itemgetter(columnnumber) ,x[0].lower()))  #!!!
>   with open(csvfilename, 'wb') as f:
> writeit = csv.writer(f)
> writeit.writerows(thedata)
>
> The line marked is the culprit.
> Any help is greatly appreciated.
>
> Thanks,
> Lee


-- 

DaveA

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute/run a *.py file, win7, py3.2..?

2012-04-15 Thread Steven D'Aprano
On Sun, 15 Apr 2012 21:30:48 -0700, vmars316 wrote:

> Greetings,
> windows7, portablePython3.2:
> What if i wanted to send myProg.py to a friend to RUN (who has python
> installed).


If your friend has Python installed, then double-clicking the .py file 
should work fine.


> Isn't there a way just to doubleClick on myProg.py, to get it into the
> interpret/RUN?

Have you tried it? What makes you think it doesn't work?


> And yes. i am interested in py2exe or the like, for windows7. And would
> like to know what's available, like py2exe.

Have you tried py2exe?


-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Steven D'Aprano
On Sun, 15 Apr 2012 13:01:54 -0700, Bryan wrote:

> Steven wrote:
>> Yes, but I have reasons for disagreeing, which you trimmed out of your
>> response. If you have reasons for thinking that a separate file
>> extension for Python 3 is a good idea, you are keeping it to yourself.
> 
> On Windows the file extension determines what executable opens the file.
> Running both Python 2 and Python 3 on Windows is painful where it
> doesn't need to be.

And how is that different from any other two versions of Python?

Unless both versions include the same libraries (either standard modules 
or third party), and your code is written to use only the lowest common 
denominator functionality, you will have problems regardless of which 
versions they are.

It is true that simple Python code using no external libraries has a 
better chance of working without modification across multiple 2.x 
versions than across the 2-3 transition, but that's not an absolute. 
Going from 2.5 to 2.6 can cause breakage; on the other hand with care you 
can support 2.6-3.2. With some extra effort, you can support 2.5 or even 
older too.

(Sufficiently trivial, or careful, code can probably support any version 
of Python from 1.4 to 3.2 inclusive. But it wouldn't be pleasant.)

The situation is worse on Windows, as Windows doesn't support hash-bang 
syntax. But that is being looked at now:

http://www.python.org/dev/peps/pep-0397/

which should make supporting multiple Python versions much more pleasant 
Real Soon Now.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to execute/run a *.py file, win7, py3.2..?

2012-04-15 Thread alex23
On Apr 16, 2:30 pm, vmars316  wrote:
> windows7, portablePython3.2:

Is there a reason why you're using Portable Python over the standard
install?

> What if i wanted to send myProg.py to a friend to RUN (who has python
> installed).
> Isn't there a way just to doubleClick on myProg.py, to get it into the
> interpret/RUN?

This is what the standard install of Python does by default under
Windows. You're missing the environment setup because you're using
Portable Python. If you absolutely must use it, you might get better
answers from https://groups.google.com/group/portablepython

> Could i RUN a myProg.o ?

Yes, you can run .pyc & .pyo files:

Z:\>cat test.py
print "foo"

Z:\>python -O -m py_compile test.py

Z:\>del test.py

Z:\>python test.pyo
foo

Z:\>test.pyo
foo

> There must be a way to initiate the RUNning of a myProg.py without
> IDLE or pyScript, or the like.

There is: use a non-portable version of Python, or launch it by
explicitly prefixing it with 'python'.

> What if i wanted to write my own program in maybe "C",
> who's job it is to initiate interpret/run any *.py program.

Um, yours, who else is going to do it for you?

> How does IDLE or pyScript do it?

I've never had to look into it because it always just works when using
a system-installed Python.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread alex23
On Apr 16, 3:34 pm, Steven D'Aprano  wrote:
> The situation is worse on Windows, as Windows doesn't support hash-bang
> syntax. But that is being looked at now:
>
> http://www.python.org/dev/peps/pep-0397/
>
> which should make supporting multiple Python versions much more pleasant
> Real Soon Now.

I keep hoping it will, but it's still in draft & I haven't seen much
motion lately :(

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Paul Rubin
Steven D'Aprano  writes:
>> Running both Python 2 and Python 3 on Windows is painful where it
>> doesn't need to be.
> And how is that different from any other two versions of Python?

1. The backwards incompatibility between 2 and 3 is much more serious
than between 2.x and 2.(x-1).  

2. There is not much reason to run multiple 2.x's on the same system.

> Going from 2.5 to 2.6 can cause breakage; 

That should be considered a bug in 2.6, but in any case it doesn't come
into play that often.  It's nothing like the 3.x changes.

> on the other hand with care you can support 2.6-3.2. 

The idea of the incompatibilities introduced to 3.x is that people
should USE them, since they supposedly make the language better.
Therefore "with care" goes against their purpose.  Also, "with care"
only applies to script you write yourself.  If you download a script
from somewhere else that relies on 3.x, you have to modify it to work
under 2.x and vice versa.  If you download both kinds of scripts you
have to modify some of them or else run two Pythons.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sort by column a csv file case insensitive

2012-04-15 Thread Peter Otten
Lee Chaplin wrote:

> Hi all,
> 
> I am trying to sort, in place, by column, a csv file AND sort it case
> insensitive.
> I was trying something like this, with no success:
> 
> import csv
> import operator
> 
> def sortcsvbyfield(csvfilename, columnnumber):
>   with open(csvfilename, 'rb') as f:
> readit = csv.reader(f)
> thedata = list(readit)
> 
>   thedata = sorted(thedata, key = lambda x:
> (operator.itemgetter(columnnumber) ,x[0].lower()))  #!!!
>   with open(csvfilename, 'wb') as f:
> writeit = csv.writer(f)
> writeit.writerows(thedata)
> 
> The line marked is the culprit.
> Any help is greatly appreciated.


Try out your sort key on interactively:

>>> import csv
>>> import operator
>>> columnnumber = 0
>>> sortkey = lambda x: (operator.itemgetter(columnnumber), x[0].lower())
>>> sortkey(["an", "example", "row"])
(, 'an')
>>> sortkey(["an", "example", "row"])
(, 'an')
>>> sortkey(["an", "example", "row"])
(, 'an')

Effectively you are sorting your data by the id (memory address) of the 
itemgetters you create. You probably want

>>> def sortkey(row):
... column = row[columnnumber]
... return column.lower(), column
... 
>>> sorted([[col] for col in "alpha ALPHA beta GAMMA gamma".split()], 
key=sortkey)
[['ALPHA'], ['alpha'], ['beta'], ['GAMMA'], ['gamma']]

Alternatively you can use

>>> import locale
>>> locale.setlocale(locale.LC_ALL, "")
'de_DE.UTF-8'
>>> sorted([[col] for col in "alpha ALPHA beta GAMMA gamma".split()], 
key=lambda row: locale.strxfrm(row[columnnumber]))
[['alpha'], ['ALPHA'], ['beta'], ['gamma'], ['GAMMA']]


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python Gotcha's?

2012-04-15 Thread Bryan
Steven D'Aprano wrote:
> And how is that different from any other two versions of Python?

Python 3.0, also known as “Python 3000” or “Py3K”, is the first ever
*intentionally backwards incompatible* Python release. --GVR

> Unless both versions include the same libraries (either standard modules
> or third party), and your code is written to use only the lowest common
> denominator functionality, you will have problems regardless of which
> versions they are.

*My* code is not what's holding me back. I *like* moving my code to
Python 3. What's holding me back is library availability, and from
various readings on the transition to 3, I gather that's what holding
many, perhaps most, users back.

The need to keep using 2.x should not stop users from installing and
starting to muck with 3.0. That's much more painful than it has to be
because they both use the same file extension.

--
--Bryan


-- 
http://mail.python.org/mailman/listinfo/python-list