[Tutor] server used in python

2011-03-28 Thread ema francis
I am learnning python for  3 months from now. I wanted to know how and what
*server* is used in python web development?Looking for your help 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to read remote text file?

2011-03-28 Thread Ratna Banjara
Hey all,

I need to read text file from remote server and generate excel file from
local computer using python. Is it possible? If so how?

-- 
Regards,
Ratna P Banjara
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to read remote text file?

2011-03-28 Thread Steven D'Aprano

Ratna Banjara wrote:

Hey all,

I need to read text file from remote server and generate excel file from
local computer using python. Is it possible? If so how?



Possibly. Do you have access to the server? If so, you have to download 
the file using whatever protocol the server supports: http, https, ftp, 
gopher, something else.


Once you have copied the file, you can read the file and write it to a 
CSV file using the csv module. Excel can read CSV files. If you need an 
actual .xls file, this is a secret, proprietary format. There are some 
projects that have tried to reverse-engineer the format, like the xlrd 
package. Google for "excel python" and you will find about 13 million hits.




--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] server used in python

2011-03-28 Thread Steven D'Aprano

ema francis wrote:

I am learnning python for  3 months from now. I wanted to know how and what
*server* is used in python web development?Looking for your help 


There are several.

I suggest you start with CherryPy:

www.cherrypy.org/




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to read remote text file?

2011-03-28 Thread Walter Prins
Hi

On 28 March 2011 11:53, Steven D'Aprano  wrote:

> There are some projects that have tried to reverse-engineer the format,
> like the xlrd package.
>

Yes, just to add, xlrd is the "reader" module, the Excel "writer" is xlwt,
available here: http://pypi.python.org/pypi/xlwt

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] server used in python

2011-03-28 Thread James Thornton
On Mon, Mar 28, 2011 at 3:27 AM, ema francis  wrote:
> I am learnning python for  3 months from now. I wanted to know how and what
> server is used in python web development?Looking for your help 

When you're developing a Python Web application, most people use a
development server that automatically detects when you update a file
and reloads it for you so you don't have to restart the Web server
each time.

When you're ready to take your site live, you have several options. If
you design your Web application as a WSGI app
(http://www.wsgi.org/wsgi/), you can hook into any WSGI server. Many
people use Apache with mod_wsgi, but you can also proxy back to your
Web app.

Look at using the Flask Web Framework (http://flask.pocoo.org/docs/).
Flask is a modern, lightweight, and well-documented Python Web
framework so you won't have to spend much time learning it or fighting
with it so you won't find yourself asking, "Will I be able to do what
I want in the framework without hacking it?"

Flask let's you program in Python rather than writing to the framework
like you typically have to in larger, opinionated framework's like
Django and Rails. It comes with a development server, and its
documentation (http://flask.pocoo.org/docs/) explains several
different types of deployment options for when you're ready to go live
(http://flask.pocoo.org/docs/deploying/).

- James

-- 
Latest Blog: http://jamesthornton.com/blog/how-to-get-to-genius
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Write new line(enter) in txt

2011-03-28 Thread Susana Iraiis Delgado Rodriguez
Hello list!!

This is a very simple question!! I want to write some lines in a txt file,
but my output looks like this:
No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo
existe el archivo C:\índice_raster.dbf
I need it to look like this:
No existe el archivo C:\índice.dbf
No existe el archivo C:\índice_dwg.dbf
No existe el archivo C:\índice_raster.dbf

The code I wrote is:
log = open ('errors.txt','wb')
shp = 'Error al abrir el archivo' +filepath
log.write(shp+"\n")
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
dbf = n[0]+'.dbf'
if os.path.exists(shx):
print 'El archivo ' +shx +' existe'
else:
log.write('No existe el archivo ' +shx+"\n")
if os.path.exists(dbf):
print 'El archivo ' +dbf +' existe'
else:
log.write('No existe el archivo ' +dbf+"\n")
log.close()
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Write new line(enter) in txt

2011-03-28 Thread Joel Goldstick
On Mon, Mar 28, 2011 at 11:12 AM, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> Hello list!!
>
> This is a very simple question!! I want to write some lines in a txt file,
> but my output looks like this:
> No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo
> existe el archivo C:\índice_raster.dbf
> I need it to look like this:
> No existe el archivo C:\índice.dbf
> No existe el archivo C:\índice_dwg.dbf
> No existe el archivo C:\índice_raster.dbf
>
> The code I wrote is:
> log = open ('errors.txt','wb')
> shp = 'Error al abrir el archivo' +filepath
> log.write(shp+"\n")
> n = os.path.splitext(filepath)
> p = n[0]+'.prj'
> shx = n[0]+'.shx'
> dbf = n[0]+'.dbf'
> if os.path.exists(shx):
> print 'El archivo ' +shx +' existe'
> else:
> log.write('No existe el archivo ' +shx+"\n")
> if os.path.exists(dbf):
> print 'El archivo ' +dbf +' existe'
> else:
> log.write('No existe el archivo ' +dbf+"\n")
> log.close()
>
>
> Windows systems I believe need cr/lf for end of line character.  You should
first try opening your file in text mode, not binary.  Then your \n will be
translated into whatever end of line sequence your operating system
requires.


http://docs.python.org/tutorial/inputoutput.html#reading-and-writing-files


> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pygame install help

2011-03-28 Thread Wayne Werner
On Sun, Mar 27, 2011 at 12:31 PM, Chuck  wrote:

> Does anyone have familiarity with installing pygame? It seems simple and
> straight forward enough, then why do I get the following from IDLE? This is
> the 3.1 Windows pygame .msi install...
>
> Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)]
> on win32
> Type "copyright", "credits" or "license()" for more information.
> >>> import pygame
> Traceback (most recent call last):
>   File "", line 1, in 
> import pygame
>   File "C:\Python32\lib\site-
> packages\pygame\__init__.py", line 95, in 
> from pygame.base import *
> ImportError: DLL load failed: The specified module could not be found.
> >>>
>

Pygame support for Python 3 is a bit spotty (AFAIK). It will probably be
easier using an earlier version of Python when working with Pygame.

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Write new line(enter) in txt

2011-03-28 Thread Susana Iraiis Delgado Rodriguez
Ok Flyyn!
Thank you for answered my question. I think I didn't explain what I need.
The printing statement is used to print a message to  the Windows console,
then the other line written in the else statement is:
log.write('No existe el archivo ' +shx+"\n")
This is the part I'm struggling with, I don't know how to add the "new line"
to the txt

2011/3/28 Flynn, Stephen (L & P - IT) 

> You don't "print" a newline when you print each line of the file
> contents...
>
>
> print 'El archivo ' +shx +' existe'
>
>
>
>
>
> You need to add a newline:
>
> print 'El archivo ' +shx +' existe' + '\n'
>
>
>
>
> 
> From: tutor-bounces+steve.flynn=capita.co...@python.org [mailto:
> tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of Susana
> Iraiis Delgado Rodriguez
> Sent: Monday, March 28, 2011 4:12 PM
> To: tutor@python.org
> Subject: [Tutor] Write new line(enter) in txt
>
> Hello list!!
>
> This is a very simple question!! I want to write some lines in a txt file,
> but my output looks like this:
> No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo
> existe el archivo C:\índice_raster.dbf
> I need it to look like this:
> No existe el archivo C:\índice.dbf
> No existe el archivo C:\índice_dwg.dbf
> No existe el archivo C:\índice_raster.dbf
>
> The code I wrote is:
> log = open ('errors.txt','wb')
> shp = 'Error al abrir el archivo' +filepath
> log.write(shp+"\n")
> n = os.path.splitext(filepath)
> p = n[0]+'.prj'
> shx = n[0]+'.shx'
> dbf = n[0]+'.dbf'
> if os.path.exists(shx):
> print 'El archivo ' +shx +' existe'
> else:
> log.write('No existe el archivo ' +shx+"\n")
> if os.path.exists(dbf):
> print 'El archivo ' +dbf +' existe'
> else:
> log.write('No existe el archivo ' +dbf+"\n")
> log.close()
>
>
> This email has been scanned for all viruses by the MessageLabs SkyScan
> service.
>
> This email and any attachment to it are confidential.  Unless you are the
> intended recipient, you may not use, copy or disclose either the message or
> any information contained in the message. If you are not the intended
> recipient, you should delete this email and notify the sender immediately.
>
> Any views or opinions expressed in this email are those of the sender only,
> unless otherwise stated.  All copyright in any Capita material in this email
> is reserved.
>
> All emails, incoming and outgoing, may be recorded by Capita and monitored
> for legitimate business purposes.
>
> Capita exclude all liability for any loss or damage arising or resulting
> from the receipt, use or transmission of this email to the fullest extent
> permitted by law.
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Write new line(enter) in txt

2011-03-28 Thread Joel Goldstick
On Mon, Mar 28, 2011 at 11:28 AM, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> Ok Flyyn!
> Thank you for answered my question. I think I didn't explain what I need.
> The printing statement is used to print a message to  the Windows console,
> then the other line written in the else statement is:
>
> log.write('No existe el archivo ' +shx+"\n")
> This is the part I'm struggling with, I don't know how to add the "new
> line" to the txt
>
> 2011/3/28 Flynn, Stephen (L & P - IT) 
>
>> You don't "print" a newline when you print each line of the file
>> contents...
>>
>>
>>
>> print 'El archivo ' +shx +' existe'
>>
>>
>>
>>
>>
>> You need to add a newline:
>>
>> print 'El archivo ' +shx +' existe' + '\n'
>>
>>
>>
>>
>> 
>> From: tutor-bounces+steve.flynn=capita.co...@python.org [mailto:
>> tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of Susana
>> Iraiis Delgado Rodriguez
>> Sent: Monday, March 28, 2011 4:12 PM
>> To: tutor@python.org
>> Subject: [Tutor] Write new line(enter) in txt
>>
>>
>> Hello list!!
>>
>> This is a very simple question!! I want to write some lines in a txt file,
>> but my output looks like this:
>> No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo
>> existe el archivo C:\índice_raster.dbf
>> I need it to look like this:
>> No existe el archivo C:\índice.dbf
>> No existe el archivo C:\índice_dwg.dbf
>> No existe el archivo C:\índice_raster.dbf
>>
>> The code I wrote is:
>> log = open ('errors.txt','wb')
>>
>

Change the above line to
  log = open('errors.txt, 'w')

You are opening your log file in binary mode, so your operating system
doesn't convert your '\n' to what it needs for new line


> shp = 'Error al abrir el archivo' +filepath
>> log.write(shp+"\n")
>> n = os.path.splitext(filepath)
>> p = n[0]+'.prj'
>> shx = n[0]+'.shx'
>> dbf = n[0]+'.dbf'
>> if os.path.exists(shx):
>> print 'El archivo ' +shx +' existe'
>> else:
>> log.write('No existe el archivo ' +shx+"\n")
>> if os.path.exists(dbf):
>> print 'El archivo ' +dbf +' existe'
>> else:
>> log.write('No existe el archivo ' +dbf+"\n")
>> log.close()
>>
>>
>> This email has been scanned for all viruses by the MessageLabs SkyScan
>> service.
>>
>> This email and any attachment to it are confidential.  Unless you are the
>> intended recipient, you may not use, copy or disclose either the message or
>> any information contained in the message. If you are not the intended
>> recipient, you should delete this email and notify the sender immediately.
>>
>> Any views or opinions expressed in this email are those of the sender
>> only, unless otherwise stated.  All copyright in any Capita material in this
>> email is reserved.
>>
>> All emails, incoming and outgoing, may be recorded by Capita and monitored
>> for legitimate business purposes.
>>
>> Capita exclude all liability for any loss or damage arising or resulting
>> from the receipt, use or transmission of this email to the fullest extent
>> permitted by law.
>>
>
>
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Write new line(enter) in txt

2011-03-28 Thread Flynn, Stephen (L & P - IT)
Ahhh - my mistake.

You open your file in binary mode - open it in text mode instead and the '\n' 
will be translated to '\n\r' (carriage return and line feed).

I do most of my coding on AIX / Unix where only the Newline is required, so 
that was the first thing I looked for... you're on Windows where an end of line 
is marked via a CR + LF.

S.


From: Susana Iraiis Delgado Rodriguez [mailto:susana.delgad...@utzmg.edu.mx] 
Sent: Monday, March 28, 2011 4:28 PM
To: Flynn, Stephen (L & P - IT)
Cc: tutor@python.org
Subject: Re: [Tutor] Write new line(enter) in txt

Ok Flyyn!
Thank you for answered my question. I think I didn't explain what I need. The 
printing statement is used to print a message to  the Windows console, then the 
other line written in the else statement is:
log.write('No existe el archivo ' +shx+"\n")
This is the part I'm struggling with, I don't know how to add the "new line" to 
the txt
2011/3/28 Flynn, Stephen (L & P - IT) 
You don't "print" a newline when you print each line of the file contents...


print 'El archivo ' +shx +' existe'




You need to add a newline:

print 'El archivo ' +shx +' existe' + '\n'





From: tutor-bounces+steve.flynn=capita.co...@python.org 
[mailto:tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of Susana 
Iraiis Delgado Rodriguez
Sent: Monday, March 28, 2011 4:12 PM
To: tutor@python.org
Subject: [Tutor] Write new line(enter) in txt

Hello list!!

This is a very simple question!! I want to write some lines in a txt file, but 
my output looks like this:
No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo 
existe el archivo C:\índice_raster.dbf
I need it to look like this:
No existe el archivo C:\índice.dbf
No existe el archivo C:\índice_dwg.dbf
No existe el archivo C:\índice_raster.dbf

The code I wrote is:
log = open ('errors.txt','wb')
shp = 'Error al abrir el archivo' +filepath
log.write(shp+"\n")
n = os.path.splitext(filepath)
p = n[0]+'.prj'
shx = n[0]+'.shx'
dbf = n[0]+'.dbf'
if os.path.exists(shx):
    print 'El archivo ' +shx +' existe'
    else:
    log.write('No existe el archivo ' +shx+"\n")
    if os.path.exists(dbf):
    print 'El archivo ' +dbf +' existe'
    else:
    log.write('No existe el archivo ' +dbf+"\n")
log.close()

This email has been scanned for all viruses by the MessageLabs SkyScan service.

This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes.

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.


This email has been scanned for all viruses by the MessageLabs SkyScan service.

This email and any attachment to it are confidential.  Unless you are the 
intended recipient, you may not use, copy or disclose either the message or any 
information contained in the message. If you are not the intended recipient, 
you should delete this email and notify the sender immediately.

Any views or opinions expressed in this email are those of the sender only, 
unless otherwise stated.  All copyright in any Capita material in this email is 
reserved.

All emails, incoming and outgoing, may be recorded by Capita and monitored for 
legitimate business purposes. 

Capita exclude all liability for any loss or damage arising or resulting from 
the receipt, use or transmission of this email to the fullest extent permitted 
by law.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Write new line(enter) in txt

2011-03-28 Thread Tommy Kaas
 

 

Fra: tutor-bounces+tommy.kaas=kaasogmulvad...@python.org
[mailto:tutor-bounces+tommy.kaas=kaasogmulvad...@python.org] På vegne af
Susana Iraiis Delgado Rodriguez
Sendt: 28. marts 2011 17:12
Til: tutor@python.org
Emne: [Tutor] Write new line(enter) in txt

 

Hello list!!

This is a very simple question!! I want to write some lines in a txt file,
but my output looks like this:
No existe el archivo C:\índice.dbfNo existe el archivo C:\índice_dwg.dbfNo
existe el archivo C:\índice_raster.dbf
I need it to look like this:
No existe el archivo C:\índice.dbf
No existe el archivo C:\índice_dwg.dbf
No existe el archivo C:\índice_raster.dbf

…
else:
log.write('No existe el archivo ' +shx+"\n")
if os.path.exists(dbf):
print 'El archivo ' +dbf +' existe'
else:
log.write('No existe el archivo ' +dbf+"\n")
log.close()

 

Try: ”\r\n” 

Tommy

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Tutor Digest, Vol 85, Issue 103

2011-03-28 Thread Susana Iraiis Delgado Rodriguez
Thank you to everyone!

I changed the txt mode for my system, from 'wb' to 'w' and finally I got
what I need.

Than you!
2011/3/28 

> Send Tutor mailing list submissions to
>tutor@python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>http://mail.python.org/mailman/listinfo/tutor
> or, via email, send a message with subject or body 'help' to
>tutor-requ...@python.org
>
> You can reach the person managing the list at
>tutor-ow...@python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Tutor digest..."
>
>
> Today's Topics:
>
>   1. Re: Pygame install help (Wayne Werner)
>   2. Re: Write new line(enter) in txt (Susana Iraiis Delgado Rodriguez)
>   3. Re: Write new line(enter) in txt (Joel Goldstick)
>
>
> --
>
> Message: 1
> Date: Mon, 28 Mar 2011 10:27:25 -0500
> From: Wayne Werner 
> To: Chuck 
> Cc: tutor@python.org
> Subject: Re: [Tutor] Pygame install help
> Message-ID:
>
> Content-Type: text/plain; charset="iso-8859-1"
>
> On Sun, Mar 27, 2011 at 12:31 PM, Chuck  wrote:
>
> > Does anyone have familiarity with installing pygame? It seems simple and
> > straight forward enough, then why do I get the following from IDLE? This
> is
> > the 3.1 Windows pygame .msi install...
> >
> > Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)]
> > on win32
> > Type "copyright", "credits" or "license()" for more information.
> > >>> import pygame
> > Traceback (most recent call last):
> >   File "", line 1, in 
> > import pygame
> >   File "C:\Python32\lib\site-
> > packages\pygame\__init__.py", line 95, in 
> > from pygame.base import *
> > ImportError: DLL load failed: The specified module could not be found.
> > >>>
> >
>
> Pygame support for Python 3 is a bit spotty (AFAIK). It will probably be
> easier using an earlier version of Python when working with Pygame.
>
> HTH,
> Wayne
> -- next part --
> An HTML attachment was scrubbed...
> URL: <
> http://mail.python.org/pipermail/tutor/attachments/20110328/4d663213/attachment-0001.html
> >
>
> --
>
> Message: 2
> Date: Mon, 28 Mar 2011 09:28:18 -0600
> From: Susana Iraiis Delgado Rodriguez 
> To: "Flynn, Stephen (L & P - IT)" 
> Cc: tutor@python.org
> Subject: Re: [Tutor] Write new line(enter) in txt
> Message-ID:
>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Ok Flyyn!
> Thank you for answered my question. I think I didn't explain what I need.
> The printing statement is used to print a message to  the Windows console,
> then the other line written in the else statement is:
> log.write('No existe el archivo ' +shx+"\n")
> This is the part I'm struggling with, I don't know how to add the "new
> line"
> to the txt
>
> 2011/3/28 Flynn, Stephen (L & P - IT) 
>
> > You don't "print" a newline when you print each line of the file
> > contents...
> >
> >
> > print 'El archivo ' +shx +' existe'
> >
> >
> >
> >
> >
> > You need to add a newline:
> >
> > print 'El archivo ' +shx +' existe' + '\n'
> >
> >
> >
> >
> > 
> > From: tutor-bounces+steve.flynn=capita.co...@python.org [mailto:
> > tutor-bounces+steve.flynn=capita.co...@python.org] On Behalf Of Susana
> > Iraiis Delgado Rodriguez
> > Sent: Monday, March 28, 2011 4:12 PM
> > To: tutor@python.org
> > Subject: [Tutor] Write new line(enter) in txt
> >
> > Hello list!!
> >
> > This is a very simple question!! I want to write some lines in a txt
> file,
> > but my output looks like this:
> > No existe el archivo C:\?ndice.dbfNo existe el archivo
> C:\?ndice_dwg.dbfNo
> > existe el archivo C:\?ndice_raster.dbf
> > I need it to look like this:
> > No existe el archivo C:\?ndice.dbf
> > No existe el archivo C:\?ndice_dwg.dbf
> > No existe el archivo C:\?ndice_raster.dbf
> >
> > The code I wrote is:
> > log = open ('errors.txt','wb')
> > shp = 'Error al abrir el archivo' +filepath
> > log.write(shp+"\n")
> > n = os.path.splitext(filepath)
> > p = 

[Tutor] Replying

2011-03-28 Thread markrivet
When replying to the mailing list, does everyone just hit the reply button in 
your email program. Because that sends the email directly to your email. Also 
everyone is cc'ng the mailing list; is that the exceptable way to reply so 
everyone in the list gets the replies?

Mark R Rivet, Genesis Software Consulting
ASCT(Computer Technologies), BSIT/SE(Software Engineering)
Electrical Engineering Technician
Member IEEE, Computer Society


Mark R Rivet, Genesis Software Consulting
ASCT(Computer Technologies), BSIT/SE(Software Engineering)
Electrical Engineering Technician
Member IEEE, Computer Society


Do or do not; there is no try.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying

2011-03-28 Thread Brett Ritter
On Mon, Mar 28, 2011 at 1:04 PM,   wrote:
> When replying to the mailing list, does everyone just hit the reply button in 
> your email program. Because that sends the email directly to your email. Also 
> everyone is cc'ng the mailing list; is that the exceptable way to reply so 
> everyone in the list gets the replies?

Fully functional email clients (generally only found on Linux/BSD)
have a "reply to Group" function that works as intended.

Most email clients lack such ability, so the process on this list is
to use "Reply to All", which CC's the list as you describe.

How email lists function is an oft-debated topic.  Many (most?) lists
will make the "reply-to" header in the email reflect the list address
(instead of the original sender), so a simple "Reply" will go to the
list.  However, the "Reply To" header is not intended by the email RFC
to function this way.  It ends up in a battle of "follow the spec as
intended" vs "follow the generally expected results".  You can read
much on this debate by googling for "Reply To munging harmful" and
"Reply To munging useful", but further discussion is definitely
outside the scope of this list.

Technical mailing lists and/or long-existing mailing lists will often
take stances on subjects such as reply to, top-quoting, quote
trimming, signatures, plain text vs HTML, etc because many of those
standards came about from a time when communicating detailed and
in-depth topics over email to a large group was pretty much the only
way to communicate if not in person.  Today's web-forum lol
outlook-trained populace is generally ignorant of such reasonings, but
trust me, the rules have a reason beyond techie elitism for existing.
(*steps off soapbox*).  You can google "Eternal September" for more on
that general topic.

TL;DR Version: Yes, that's perfectly acceptable.  *bites tongue to
resist going off on a rant about TL;DR*

Hope that was helpful!
-- 
Brett Ritter / SwiftOne
swift...@swiftone.org
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying

2011-03-28 Thread Corey Richardson
On 03/28/2011 01:04 PM, markri...@gsoftcon.com wrote:
> When replying to the mailing list, does everyone just hit the reply button in 
> your email program. Because that sends the email directly to your email. Also 
> everyone is cc'ng the mailing list; is that the exceptable way to reply so 
> everyone in the list gets the replies?
> 

Thunderbird has a "reply list" button that I use.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Read arguments from command line

2011-03-28 Thread Susana Iraiis Delgado Rodriguez
Hello everyone!

I want to run a python script which reads arguments from command line. I
searched in web and the module sys.argv came up. But I don't understand how
it works. I need to know how to pass arguments from command line and make
the python script works from MS-DOS instead of run my program from the
python console.

Is there any documentation?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read arguments from command line

2011-03-28 Thread Blockheads Oi Oi

On 28/03/2011 18:24, Susana Iraiis Delgado Rodriguez wrote:

Hello everyone!

I want to run a python script which reads arguments from command line. I
searched in web and the module sys.argv came up. But I don't understand
how it works. I need to know how to pass arguments from command line and
make the python script works from MS-DOS instead of run my program from
the python console.

Is there any documentation?



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
See this from a well known Python tutorial 
http://www.faqs.org/docs/diveintopython/kgp_commandline.html


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Read arguments from command line

2011-03-28 Thread Joel Goldstick
On Mon, Mar 28, 2011 at 1:24 PM, Susana Iraiis Delgado Rodriguez <
susana.delgad...@utzmg.edu.mx> wrote:

> Hello everyone!
>
> I want to run a python script which reads arguments from command line. I
> searched in web and the module sys.argv came up. But I don't understand how
> it works. I need to know how to pass arguments from command line and make
> the python script works from MS-DOS instead of run my program from the
> python console.
>
> Is there any documentation?
>
>
if you have the following command:
python myprogram.py first second third

sys.argv[0] will be "myprogram.py"
sys.argv[1] will be "first"
sys.argv[2] will be "second"

and so forth

If you need more complicated command line parsing you should look into
argparse


___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Joel Goldstick
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Pygame install help

2011-03-28 Thread Jerry Hill
On Sun, Mar 27, 2011 at 1:31 PM, Chuck  wrote:
> Does anyone have familiarity with installing pygame? It seems simple and
> straight forward enough, then why do I get the following from IDLE? This is
> the 3.1 Windows pygame .msi install...

You're using pygame (probably pygame 1.9.1) built for python 3.1, but...

> Python 3.2 (r32:88445, Feb 20 2011, 21:29:02) [MSC v.1500 32 bit (Intel)] on

...you're using python 3.2.

Don't do that.  Your versions need to match.  Since I don't see a
version of pygame built for python 3.2 on windows, you'll need to
either go back to python 3.1, or wait for someone to build pygame for
3.2.  You might be able to build it yourself, but I don't know how
convoluted that is.

-- 
Jerry
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to optimize this code?

2011-03-28 Thread Albert-Jan Roskam
Hi Stefan,

Thanks for your advice. I seriously thought ctypes was the module to use. That 
was before I found out the evaluating all 10**9 values of my test data set is 
glacially slow (several hours). You're right, the dll implies the program is 
running on windows. I've also been trying to make it work under Linux but I 
wanted to get the basic algorithm right first. Also, it was quite a PIA to get 
all the dependencies of the (old) .so files.

Your speed tip reminded me of: 
http://wiki.python.org/moin/PythonSpeed/PerformanceTips#Avoiding_dots...
Does this mean that "from ctypes import *" gives slightly faster code than 
"import ctypes"? If so: wow! I've always avoided the first notation like the 
plague.

What do you mean with '... using a constant pointer for numValue' ? Is this the 
byref/pointer object distinction? I replaced a the pointer object with a byref 
object, which reduced processing time by about 10 %.

Cython might be interesting as a hobby project, but I'm affraid I'll never get 
the ICT droids in my office to install that.
 

 Cheers!!
Albert-Jan


~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the 
Romans ever done for us?
~~





From: Stefan Behnel 
To: tutor@python.org
Sent: Mon, March 28, 2011 7:43:16 AM
Subject: Re: [Tutor] how to optimize this code?

Albert-Jan Roskam, 27.03.2011 21:57:
> I made a program that reads spss data files. I ran cProfile to see if I can
> optimize things (see #1 below).

First thing to note here: sort the output by "time", which refers to the 
"tottime" column. That will make it more obvious where most time is really 
spent.


> It seems that the function getValueNumeric is a pain spot (see #2
> below). This function calls a C function in a dll for each numerical
> cell value. On the basis of this limited amount of info, what could I do
> to further optimize the code? I heard about psyco, but I didn't think
> such tricks would be necessary as the function spssGetValueNumeric is is
> implemented in C already (which should be fast).

The problem is that you are using ctypes to call it. It's useful for simple 
things, but it's not usable for performance critical things, such as calling a 
C 
function ten million times in your example. Since you're saying "dll", is this 
under Windows? It's a bit more tricky to set up Cython on that platform than on 
pretty much all others, since you additionally need to install a C compiler, 
but 
if you want to go that route, it will reward you with a much faster way to call 
your C code, and will allow you to also speed up the code that does the calls.

That being said, see below.


> ## most time consuming function
> 
>   def getValueNumeric(fh, spssio, varHandle):
>  numValue = ctypes.c_double()
>  numValuePtr = ctypes.byref(numValue)
>  retcode = spssio.spssGetValueNumeric(fh,
> ctypes.c_double(varHandle),
> numValuePtr)

You may still be able to make this code a tad faster, by avoiding the function 
name lookups on both the ctypes module and "spssio", and by using a constant 
pointer for numValue (is you're not using threads). That may not make enough of 
a difference, but it should at least be a little faster.

Stefan

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to optimize this code?

2011-03-28 Thread Emile van Sebille

On 3/28/2011 12:37 PM Albert-Jan Roskam said...

Hi Stefan,

Thanks for your advice. I seriously thought ctypes was the module to
use. That was before I found out the evaluating all 10**9 values of my
test data set is glacially slow (several hours). You're right, the dll
implies the program is running on windows. I've also been trying to make
it work under Linux but I wanted to get the basic algorithm right first.
Also, it was quite a PIA to get all the dependencies of the (old) .so files.

Your speed tip reminded me of:
http://wiki.python.org/moin/PythonSpeed/Performan ceTips#Avoiding_dots
...
Does this mean that "from ctypes import *"


That's not necessary.  You can also make them local by performing the 
name lookup only once:


  import ctypes
  myXxx = ctypes.Xxx

Then use myXxx going forward.



gives slightly faster code
than "import ctypes"? If so: wow! I've always avoided the first notation
like the plague.

What do you mean with '... using a constant pointer for numValue' ?


It looks like your function can reuse a once-set value where you set 
numValue outside your function and refer to it.


Emile




Is
this the byref/pointer object distinction? I replaced a the pointer
object with a byref object, which reduced processing time by about 10 %.

Cython might be interesting as a hobby project, but I'm affraid I'll
never get the ICT droids in my office to install that.

Cheers!!
Albert-Jan

~~
All right, but apart from the sanitation, the medicine, education, wine,
public order, irrigation, roads, a fresh water system, and public
health, what have the Romans ever done for us?
~~


*From:* Stefan Behnel 
*To:* tutor@python.org
*Sent:* Mon, March 28, 2011 7:43:16 AM
*Subject:* Re: [Tutor] how to optimize this code?

Albert-Jan Roskam, 27.03.2011 21:57:
 > I made a program that reads spss data files. I ran cProfile to see if
I can
 > optimize things (see #1 below).

First thing to note here: sort the output by "time", which refers to the
"tottime" column. That will make it more obvious where most time is
really spent.


 > It seems that the function getValueNumeric is a pain spot (see #2
 > below). This function calls a C function in a dll for each numerical
 > cell value. On the basis of this limited amount of info, what could I do
 > to further optimize the code? I heard about psyco, but I didn't think
 > such tricks would be necessary as the function spssGetValueNumeric is is
 > implemented in C already (which should be fast).

The problem is that you are using ctypes to call it. It's useful for
simple things, but it's not usable for performance critical things, such
as calling a C function ten million times in your example. Since you're
saying "dll", is this under Windows? It's a bit more tricky to set up
Cython on that platform than on pretty much all others, since you
additionally need to install a C compiler, but if you want to go that
route, it will reward you with a much faster way to call your C code,
and will allow you to also speed up the code that does the calls.

That being said, see below.


 > ## most time consuming function
 >
 > def getValueNumeric(fh, spssio, varHandle):
 > numValue = ctypes.c_double()
 > numValuePtr = ctypes.byref(numValue)
 > retcode = spssio.spssGetValueNumeric(fh,
 > &n bsp; ctypes.c_double(varHandle),
 > numValuePtr)

You may still be able to make this code a tad faster, by avoiding the
function name lookups on both the ctypes module and "spssio", and by
using a constant pointer for numValue (is you're not using threads).
That may not make enough of a difference, but it should at least be a
little faster.

Stefan

___
Tutor maillist - Tutor@python.org 
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] List sorting issues

2011-03-28 Thread Eric Stevens
I am currently designing an address book program, and am trying to design a
method for organizing the keys (which are the names of the entries) for
displaying purposes. I have created a list by doing sortedKeys =
self.addbook.keys() {the self.addbook refers to a dictionary in a custom
class}, and then i try to do a sortedKeys.sort() but never get an
alphabetical list of the keys. All i get is 'None'. I know that a
'list.sort()' returns a None value but all of the tutorials I see show this
giving an alphabetized list.

 I have also tried doing a 'sorted(self.addbook)' which gives me a list but
not alphabetized. The dictionary keys I am using are 'Eric', 'Kyle', and
'dfd' and they always appear in that order when i use the sorted() feature
(obviously not alphabetized).

 Could you please let me know what I am doing wrong or let me know of
another way to alphabetize an iterable object. Thank you.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying

2011-03-28 Thread Steven D'Aprano

markri...@gsoftcon.com wrote:

When replying to the mailing list, does everyone just hit the reply button in 
your email program. Because that sends the email directly to your email. Also 
everyone is cc'ng the mailing list; is that the exceptable way to reply so 
everyone in the list gets the replies?


Depends on the mail client I am using to reply.

In mutt or kmail, I hit "Reply to list", and the reply just goes to the 
list.


In Thunderbird, I use "Reply All", and edit the recipients by hand so 
that it just goes to the list, and curse the Thunderbird developers.



You should not reply to the individual unless you have something private 
to tell them. Keep replies on the list, for the benefit of anyone else 
reading.


Personally, I get annoyed when people CC me on replies that I'm also 
getting from the list, but I've long since stopped trying to hold the 
tide back :)



Thank you for asking, and welcome!


--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying

2011-03-28 Thread Steven D'Aprano

Corey Richardson wrote:


Thunderbird has a "reply list" button that I use.


It does? What version are you using?


--
Steven

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] User Made Dictionaries

2011-03-28 Thread michael scott
Hello, I'm trying to find out the best course of action for the next stage of 
my 
program.

I want to hold information on various idols. I first thought to do this with 
classes, but realised that I could represent the data the same way with a 
dictionary. So I am now just concentrating on dictionaries. 


So lets say for example I wanted to have a dictionary with keys like this.

chiaki = { "name" : "Chiaki Kuriyama",
 "age": "26",
 "charm_point" : "nose",
 "profile_pic" : 
"/home/jigenbakuda/Pictures/chiaki/chiaki.jpg",
 "pic_quantity"  : 120,
 "bio"  : "First met this lady in kill bill, 
and 
the descent afterwards was horrible, I fan boy over this chick hard, etc..."}


I understand, or at least I have pretty good ideas about how to get this 
information (the keys and their values) from a user. 


I was thinking something like this for my general flow (this is all just fake 
code trying to represent my thought process)

mold =  { "name"  : " ",
 "age": " ",
 "charm_point" : " ",
 "profile_pic" : " ",
 "pic_quantity"  : 0 ,
 "bio"  : " "}


chiaki = copy.copy(mold)
#have the user fill in the data here
natalie =  copy.copy(mold)
#have the user fill in the data here
# etc...


But my question is how do I repeatedly automate new names for the  
dictionaries? 
Like how do I get the user to create the dictionary name  (chiaki, natalie, 
etc...)? 


Would it be better to represent this data with classes? If so, how do I have 
users create new class names? Ex. chiaki = Idol(), how do I get the user to 
create the chiaki name?

Any hints, answers, or links to recommended reading would be greatly 
appreciated 
:)


   

 
What is it about you... that intrigues me so?___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List sorting issues

2011-03-28 Thread Luke Paireepinart
Sort returns none because it changes your list in-place. Print your list out 
after calling sort and you should see the new one.

-
Sent from a mobile device. Apologies for brevity and top-posting.
-

On Mar 28, 2011, at 11:53 AM, Eric Stevens  wrote:

> I am currently designing an address book program, and am trying to design a 
> method for organizing the keys (which are the names of the entries) for 
> displaying purposes. I have created a list by doing sortedKeys = 
> self.addbook.keys() {the self.addbook refers to a dictionary in a custom 
> class}, and then i try to do a sortedKeys.sort() but never get an 
> alphabetical list of the keys. All i get is 'None'. I know that a 
> 'list.sort()' returns a None value but all of the tutorials I see show this 
> giving an alphabetized list.
> 
>  I have also tried doing a 'sorted(self.addbook)' which gives me a list but 
> not alphabetized. The dictionary keys I am using are 'Eric', 'Kyle', and 
> 'dfd' and they always appear in that order when i use the sorted() feature 
> (obviously not alphabetized).
> 
>  Could you please let me know what I am doing wrong or let me know of another 
> way to alphabetize an iterable object. Thank you.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List sorting issues

2011-03-28 Thread Steven D'Aprano

Eric Stevens wrote:

I am currently designing an address book program, and am trying to design a
method for organizing the keys (which are the names of the entries) for
displaying purposes. I have created a list by doing sortedKeys =
self.addbook.keys() {the self.addbook refers to a dictionary in a custom
class}, and then i try to do a sortedKeys.sort() but never get an
alphabetical list of the keys. All i get is 'None'. I know that a
'list.sort()' returns a None value but all of the tutorials I see show this
giving an alphabetized list.


If you see any tutorial showing list.sort() *returning* a sorted list, 
the tutorial is wrong. But more likely you have misunderstood what you 
are seeing.


list.sort() is an in-place list. So you have to do this:

mylist = ["Fred", "Wilma", "Barney", "Betty"]
mylist.sort()  # Returns None, which we don't bother to keep.
print(mylist)


Or you can use the sorted() function, which returns a new list, leaving 
the original alone:


mylist = ["Fred", "Wilma", "Barney", "Betty"]
print(sorted(mylist))
print(mylist)



 I have also tried doing a 'sorted(self.addbook)' which gives me a list but
not alphabetized. The dictionary keys I am using are 'Eric', 'Kyle', and
'dfd' and they always appear in that order when i use the sorted() feature
(obviously not alphabetized).


Sorting is case sensitive, so "Z" comes before "a". For case insensitive 
sorting, pass a key function to either sorted() or list.sort():


sorted(mylist, key=string.lower)  # Can also use string.upper

Technically, this is not really case-insensitive according to the (very 
complex!) rules for sorting international text, but if your data is all 
English (or at least mostly English) you won't notice the difference.




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Replying

2011-03-28 Thread Corey Richardson
On 03/28/2011 06:17 PM, Steven D'Aprano wrote:
> Corey Richardson wrote:
> 
>> Thunderbird has a "reply list" button that I use.
> 
> It does? What version are you using?

3.1.8

I don't know how it knows what a mailing list is and isn't, but it does.

After inspecting the headers of emails from a few different lists, it
appears: List-Id, Lust-Unsubscribe, List-Archive, List-Post, List-Help,
and List-Subscribe may be helping thunderbird along.
Also common among them is a "Precedence: list" header.

-- 
Corey Richardson
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] User Made Dictionaries

2011-03-28 Thread Steven D'Aprano

michael scott wrote:

I was thinking something like this for my general flow (this is all just fake 
code trying to represent my thought process)


mold =  { "name"  : " ",
 "age": " ",
 "charm_point" : " ",
 "profile_pic" : " ",
 "pic_quantity"  : 0 ,
 "bio"  : " "}


chiaki = copy.copy(mold)
#have the user fill in the data here
natalie =  copy.copy(mold)
#have the user fill in the data here
# etc...


But my question is how do I repeatedly automate new names for the  dictionaries? 
Like how do I get the user to create the dictionary name  (chiaki, natalie, 
etc...)? 



You don't.

Instead of something like this:

chiaki = {...}
natalie = {...}
...

You have a second dictionary, keyed by the names:

girls = {'chiaki': {...},
 'natalie': {...},
 ...
}


Something like this:

girls = {}

while True:
template = copy.copy(mold)
name = raw_input("What's the name of an actress?")  # See below.
if name == "exit":
 break  # Exit the loop.
#have the user fill in rest of the data here
girls[name] = template


Or you could use a real database, like sqlite, or even a *real* database.

If you are using Python 3 or better, change raw_input to input.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] finding directory of self

2011-03-28 Thread Rance Hall
I had been doing this under windows:

import os
import sys

osname = os.name
pathtocfg = os.path.dirname(sys.argv[0])
configfileloc = os.path.abspath(pathtocfg)
os.chdir(configfileloc)

to set the directory of all subsequent file lookups in a script.

It worked underwindows because the shortcuts have a "Start In"
directory listing.

I need something for Linux use that does not care about a symlink that
would be used to start the script.

The above code finds the directory the symlink is in.

I'm actually not suprised by this, it is what I expected, I just don't
understand how to fix it.

How can I do something similar to this, but find the "real" dir?
Perhaps one of the other sys.argv arguments?

Thanks for your help

Rance
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] finding directory of self

2011-03-28 Thread Wayne Werner
On Mon, Mar 28, 2011 at 6:43 PM, Rance Hall  wrote:

> I had been doing this under windows:
>
> import os
> import sys
>
> osname = os.name
> pathtocfg = os.path.dirname(sys.argv[0])
> configfileloc = os.path.abspath(pathtocfg)
> os.chdir(configfileloc)
>
> to set the directory of all subsequent file lookups in a script.
>
> It worked underwindows because the shortcuts have a "Start In"
> directory listing.
>
> I need something for Linux use that does not care about a symlink that
> would be used to start the script.
>
> The above code finds the directory the symlink is in.
>
> I'm actually not suprised by this, it is what I expected, I just don't
> understand how to fix it.
>
> How can I do something similar to this, but find the "real" dir?
> Perhaps one of the other sys.argv arguments?
>

print(os.path.realpath(__file__))

HTH,
Wayne
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem recognizing '{' character?

2011-03-28 Thread Ben Hunter
Hi,

I'm completing the Python lessons on YouTube that Google posted. At the end
of section 2 of day 2, there is a task to identify files then put them in a
zip file in any directory. The code is from the 'solution' folder, so it's
not something I wrote. I suspect I have a problem with PATHS or environment
variables. I'm new to programming in something as advanced as Python, but I
do okay with VBA - so I just feel like there's a setting up issue somewhere.
I'm on Windows 7, tried running this in Idle and from the command line.

These two work perfectly.

def get_special_paths(dirname):
  result = []
  paths = os.listdir(dirname)  # list of paths in that dir
  for fname in paths:
match = re.search(r'__(\w+)__', fname)
if match:
  result.append(os.path.abspath(os.path.join(dirname, fname)))
  return result


def copy_to(paths, to_dir):
  if not os.path.exists(to_dir):
os.mkdir(to_dir)
  for path in paths:
fname = os.path.basename(path)
shutil.copy(path, os.path.join(to_dir, fname))

This third one does not.

def zip_to(paths, zipfile):
  """Zip up all of the given files into a new zip file with the given
name."""
  cmd = 'zip -j ' + zipfile + ' ' + ' '.join(paths)
  print "Command I'm going to do:" + cmd
  (status, output) = commands.getstatusoutput(cmd)
  # If command had a problem (status is non-zero),
  # print its output to stderr and exit.
  if status:
sys.stderr.write(output)
sys.exit(1)

My command is this: >>> copyspecial.zip_to(paths, 'zippy')

But something goes wrong and it spits this out:
'{' is not recognized as an internal or external command,
operable program or batch file.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor