[Tutor] where to look for python codes

2011-09-29 Thread Praveen Singh
i am a beginner in python.i am not asking about any books here.As i have
heard one essential steps of learning is to look for some good python
codes.So, can you guys please and please suggest me some sites or some small
projects where i can find these codes?? please remember i am at a BEGINNER's
level!!

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


Re: [Tutor] where to look for python codes

2011-09-29 Thread Alan Gauld

On 29/09/11 09:27, Praveen Singh wrote:

i am a beginner in python.i am not asking about any books here.As i have
heard one essential steps of learning is to look for some good python
codes.So, can you guys please and please suggest me some sites or some
small projects where i can find these codes?? please remember i am at a
BEGINNER's level!!



We used to have a site called UselessPython for that but last time I 
visited it was down. I don't know if its been resurrected but it was a 
useful resource for that kind of thing.


Other sources are the simple tool scripts that come with Python.
Look in the Library folders and you will find various sample/tool 
folders that you can investigate.


hth,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


[Tutor] last part of my programme

2011-09-29 Thread ADRIAN KELLY

can anyone tell me why the last part of my programme wont work.  i want the 
user to have to press enter to exit but it doesn't happen through the python 
interface.
 
the programme works fine otherwise but just shuts down when finished

thanks all
 
adrian
 
  def this():


print 'hello'
print 'i am your computer'

# set the values
password='gorilla'
Given_Password=' '

#password loop
while Given_Password.lower() != password.lower():

Given_Password=raw_input ('please enter your password: ')
if Given_Password.lower()==password.lower():
print 'Password Accepted '
else:
print 'Incorrect'

def STATS():
print 'hello'
firstname=raw_input ('please enter your firstname: ')
lastname=raw_input ('please enter your lastname: ')
town=raw_input ('what town are your from? ')
county=raw_input ('what county are you from? ')
details=name+"\n"+town+"\n"+county
print " "
print details
print "thank's for your time"



this()
STATS()



input("\n\nPress the enter key to exit. ")










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


Re: [Tutor] last part of my programme

2011-09-29 Thread Christian Witts

On 2011/09/29 11:05 AM, ADRIAN KELLY wrote:
can anyone tell me why the last part of my programme wont work.  i 
want the user to have to press enter to exit but it doesn't happen 
through the python interface.


the programme works fine otherwise but just shuts down when finished

thanks all

adrian



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

You should run this from the command line to see the errors and tracebacks.
You have a `firstname` and `lastname` variable, no `name` variable.

Traceback (most recent call last):
  File "py_tutor.py", line 34, in 
STATS()
  File "py_tutor.py", line 26, in STATS
details=name+"\n"+town+"\n"+county
NameError: global name 'name' is not defined

Once you fix that with something like `name = firstname + ' ' + 
lastname` you'll get a further error


Press the enter key to exit.
Traceback (most recent call last):
  File "py_tutor.py", line 39, in 
_ = input("\n\nPress the enter key to exit. ")
  File "", line 0

Which is because input() converts the input to an integer so you would 
need to type for eg 0 then enter for it to exit without failing. 
Changing that to raw_input() like the rest of your inputs will fix that.

--

Christian Witts
Python Developer

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


Re: [Tutor] last part of my programme

2011-09-29 Thread Peter Otten
ADRIAN KELLY wrote:

> can anyone tell me why the last part of my programme wont work.  i want
> the user to have to press enter to exit but it doesn't happen through the
> python interface.
>  
> the programme works fine otherwise but just shuts down when finished

(I'm assuming you are on Windows) Open a DOS window and cd to the directory 
where you have stored your script. Invoke it with

python 

When you now enter the data your script is asking for you will at some point 
run into the error and get a so-called "traceback" and an error message. 
Here's how it looks on Linux (I've stored your script as tmp_adrian.py):

$ python tmp_adrian.py
hello
i am your computer
please enter your password: gorilla
Password Accepted
hello
please enter your firstname: peter
please enter your lastname: otten
what town are your from? won't
what county are you from? tell
Traceback (most recent call last):
  File "tmp_adrian.py", line 34, in 
STATS()
  File "tmp_adrian.py", line 26, in STATS
details=name+"\n"+town+"\n"+county
NameError: global name 'name' is not defined
$

Can you make sense of that message and find the bug that is causing it? Come 
back if not.

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


[Tutor] Mac IDE

2011-09-29 Thread Robert Johansson
Hi,

I know that there is a lot to read about different IDEs on the net but I have 
tried a couple and I'm still not pleased. My demands are not that high, when 
I'm under Windows I'm happy with IDLE (an interactive shell and debug) but the 
problem is with Mac (Python >= 2.7 and OS 10.7). IDLE had serious problems and 
TextWrangler had no interactive shell. There's a lot of other stuff to try and 
I would be grateful if someone could spare me some time on this.

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


Re: [Tutor] Mac IDE

2011-09-29 Thread sli1...@yahoo.com
I use eclipse. Overkill for you maybe but you can so anything.

Sent from my Verizon Wireless 4GLTE smartphone

- Reply message -
From: "Robert Johansson" 
To: "tutor@python.org" 
Subject: [Tutor] Mac IDE
Date: Thu, Sep 29, 2011 2:42 am
Hi, I know that there is a lot to read about different IDEs on the net but I 
have tried a couple and I’m still not pleased. My demands are not that high, 
when I’m under Windows I’m happy with IDLE (an interactive shell and debug) but 
the problem is with Mac (Python >= 2.7 and OS 10.7). IDLE had serious problems 
and TextWrangler had no interactive shell. There’s a lot of other stuff to try 
and I would be grateful if someone could spare me some time on this.  Cheers, 
Robert___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mac IDE

2011-09-29 Thread Walter Prins
Hi

On 29 September 2011 10:42, Robert Johansson
wrote:

> Hi,
>
> ** **
>
> I know that there is a lot to read about different IDEs on the net but I
> have tried a couple and I’m still not pleased. My demands are not that high,
> when I’m under Windows I’m happy with IDLE (an interactive shell and debug)
> but the problem is with Mac (Python >= 2.7 and OS 10.7). IDLE had serious
> problems and TextWrangler had no interactive shell. There’s a lot of other
> stuff to try and I would be grateful if someone could spare me some time on
> this. 
>
>
>
Well, if you're prepared to spend a bit of money, I've heard very good
things about Wingware, which is also available on Mac  (Note, not a user
myself currently, but has seen it before and been favourably impressed,
enough to suggest it here despite not currently actively using it myself.)
Link: http://wingware.com/

In terms of free/open source, there's also of course Eclipse with PyDev,
although I don't know how easily/well it integrates into the Mac ecosystem,
but suffice it to say Mac is listed as a supported platform.  I use Eclipse
with PyDev on Linux and Windows and am quite happy with it.  Links:
http://www.eclipse.org/downloads/packages/eclipse-classic-37/indigor
http://pydev.org/index.html

HTH

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


Re: [Tutor] where to look for python codes

2011-09-29 Thread Tommy Kaas
> -Oprindelig meddelelse-
> Fra: tutor-bounces+tommy.kaas=kaasogmulvad...@python.org
> [mailto:tutor-bounces+tommy.kaas=kaasogmulvad...@python.org] På
> vegne af Alan Gauld
> Sendt: 29. september 2011 10:48
> Til: tutor@python.org
> Emne: Re: [Tutor] where to look for python codes
> 
> On 29/09/11 09:27, Praveen Singh wrote:
> > i am a beginner in python.i am not asking about any books here.As i
> > have heard one essential steps of learning is to look for some good
> > python codes.So, can you guys please and please suggest me some sites
> > or some small projects where i can find these codes?? please remember
> > i am at a BEGINNER's level!!
> 
> 
> We used to have a site called UselessPython for that but last time I
visited it
> was down. I don't know if its been resurrected but it was a useful
resource
> for that kind of thing.

Uselesspython is down, but you can reach a lot of the stuff through
archive.org:
http://web.archive.org/web/20080719092030/http://www.uselesspython.com/

Tommy

> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
> 
> -
> Ingen virus fundet i denne meddelelse.
> Kontrolleret af AVG - www.avg.com
> Version: 10.0.1410 / Virusdatabase: 1520/3925 - Udgivelsesdato: 28-09-
> 2011

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


Re: [Tutor] Mac IDE

2011-09-29 Thread Wayne Werner
On Thu, Sep 29, 2011 at 5:50 AM, Walter Prins  wrote:

> On 29 September 2011 10:42, Robert Johansson  > wrote:
>
>> Hi,
>>
>> ** **
>>
>> I know that there is a lot to read about different IDEs on the net but I
>> have tried a couple and I’m still not pleased. My demands are not that high,
>> when I’m under Windows I’m happy with IDLE (an interactive shell and debug)
>> but the problem is with Mac (Python >= 2.7 and OS 10.7). IDLE had serious
>> problems and TextWrangler had no interactive shell. There’s a lot of other
>> stuff to try and I would be grateful if someone could spare me some time on
>> this. 
>>
>>
>>
> Well, if you're prepared to spend a bit of money, I've heard very good
> things about Wingware, which is also available on Mac  (Note, not a user
> myself currently, but has seen it before and been favourably impressed,
> enough to suggest it here despite not currently actively using it myself.)
> Link: http://wingware.com/


I'll second that. If you're really into IDEs, Wingware is a great one - they
also have a student/open source license that may be right up your alley.

My personal favorite?

Two terminal windows - one with Vim, editing my Python scripts, and another
with an interactive interpreter. Since you can map keys in Vim, I have 
mapped to save and run current file. If you're in the habit of editing
multiple files you could set it up to map  to ask which file you want to
set as your main .py file. And since you mentioned debug, I usually just use
pdb if I need debugging. You could easily map a key such as  to insert a
new line and type 'pdb.set_trace()'. Vim has a fairly steep learning curve,
but if you spend 30 minutes with the vimtutor you'll be fine. With newer
versions of Vim you can also write plugins for them in Python.

Of course these capabilities (and many many more) are available with Emacs.

I personally recommend that you learn one (or both) of these editors. They
will highly improve the speed at which you are able to edit your code.

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


Re: [Tutor] where to look for python codes

2011-09-29 Thread Chris Fuller

Unless you are explicitly reading a tutorial, the code you will be looking at 
isn't going to be beginner-level in general, but you can look at smaller 
snippets and libraries then work up from that.

http://effbot.org/zone/
http://code.activestate.com/recipes/langs/python/
http://pypi.python.org/pypi
http://www.doughellmann.com/projects/PyMOTW/
http://www.secnetix.de/olli/Python/

There's plenty of good links right on the Python web site for beginners:
http://wiki.python.org/moin/BeginnersGuide

Cheers


On Thursday 29 September 2011, Praveen Singh wrote:
> i am a beginner in python.i am not asking about any books here.As i have
> heard one essential steps of learning is to look for some good python
> codes.So, can you guys please and please suggest me some sites or some
> small projects where i can find these codes?? please remember i am at a
> BEGINNER's level!!
> 
> thank you!!
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
Hi,

I want to read a bunch of *.doc file in present working directory,

how can I use for to read one by one and do further work,

sorry,

what's the best reference webpage I can use?

I googled, lots of distracting info, and I barely can understand how they
think.

THanks,

-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Tim Golden

On 29/09/2011 15:22, lina wrote:

I want to read a bunch of *.doc file in present working directory,

how can I use for to read one by one and do further work,

sorry,

what's the best reference webpage I can use?

I googled, lots of distracting info, and I barely can understand how
they think.


Try these:

http://docs.python.org/library/glob.html

http://www.doughellmann.com/PyMOTW/glob/index.html

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 10:25 PM, Tim Golden  wrote:

> On 29/09/2011 15:22, lina wrote:
>
>> I want to read a bunch of *.doc file in present working directory,
>>
>> how can I use for to read one by one and do further work,
>>
>> sorry,
>>
>> what's the best reference webpage I can use?
>>
>> I googled, lots of distracting info, and I barely can understand how
>> they think.
>>
>
> Try these:
>
> http://docs.python.org/**library/glob.html
>
> http://www.doughellmann.com/**PyMOTW/glob/index.html
>

Thanks,


import glob

for FILE in glob.glob('*.xpm'):
print FILE

How do I not print FILE,
I want to put those files in a for loop

and then further to read one by one,

Thanks,


>
> TJG
>



-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Dave Angel

On 09/29/2011 10:22 AM, lina wrote:

Hi,

I want to read a bunch of *.doc file in present working directory,

how can I use for to read one by one and do further work,

sorry,

what's the best reference webpage I can use?

I googled, lots of distracting info, and I barely can understand how they
think.

THanks,


Look in the os module for things like this.  In particular (untested):

import os.path

for fileName in os.listdir(".")
if os.path.isfile(fileName) and os.path.splitext(fileName) == "doc":
filedata = open(fileName)
xxxdosomething with filedata



--

DaveA

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


Re: [Tutor] Mac IDE

2011-09-29 Thread Tom Tucker
Another IDE to consider that supports the MAC OS is PyCharm from JetBrains.

On Thu, Sep 29, 2011 at 7:50 AM, Wayne Werner wrote:

> On Thu, Sep 29, 2011 at 5:50 AM, Walter Prins  wrote:
>
>> On 29 September 2011 10:42, Robert Johansson <
>> robert.johans...@math.umu.se> wrote:
>>
>>> Hi,
>>>
>>> ** **
>>>
>>> I know that there is a lot to read about different IDEs on the net but I
>>> have tried a couple and I’m still not pleased. My demands are not that high,
>>> when I’m under Windows I’m happy with IDLE (an interactive shell and debug)
>>> but the problem is with Mac (Python >= 2.7 and OS 10.7). IDLE had serious
>>> problems and TextWrangler had no interactive shell. There’s a lot of other
>>> stuff to try and I would be grateful if someone could spare me some time on
>>> this. 
>>>
>>>
>>>
>> Well, if you're prepared to spend a bit of money, I've heard very good
>> things about Wingware, which is also available on Mac  (Note, not a user
>> myself currently, but has seen it before and been favourably impressed,
>> enough to suggest it here despite not currently actively using it myself.)
>> Link: http://wingware.com/
>
>
> I'll second that. If you're really into IDEs, Wingware is a great one -
> they also have a student/open source license that may be right up your
> alley.
>
> My personal favorite?
>
> Two terminal windows - one with Vim, editing my Python scripts, and another
> with an interactive interpreter. Since you can map keys in Vim, I have 
> mapped to save and run current file. If you're in the habit of editing
> multiple files you could set it up to map  to ask which file you want to
> set as your main .py file. And since you mentioned debug, I usually just use
> pdb if I need debugging. You could easily map a key such as  to insert a
> new line and type 'pdb.set_trace()'. Vim has a fairly steep learning curve,
> but if you spend 30 minutes with the vimtutor you'll be fine. With newer
> versions of Vim you can also write plugins for them in Python.
>
> Of course these capabilities (and many many more) are available with Emacs.
>
> I personally recommend that you learn one (or both) of these editors. They
> will highly improve the speed at which you are able to edit your code.
>
> HTH,
> Wayne
>
> ___
> 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] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
import os.path

tokens=['E']
result=[]

for fileName in os.listdir("."):
if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
filedata = open(fileName)
text=filedata.readlines()
for line in text:


How can I read from line 24 and do further looking for "E".

Thanks,


On Thu, Sep 29, 2011 at 10:43 PM, Dave Angel  wrote:

> On 09/29/2011 10:22 AM, lina wrote:
>
>> Hi,
>>
>> I want to read a bunch of *.doc file in present working directory,
>>
>> how can I use for to read one by one and do further work,
>>
>> sorry,
>>
>> what's the best reference webpage I can use?
>>
>> I googled, lots of distracting info, and I barely can understand how they
>> think.
>>
>> THanks,
>>
>>  Look in the os module for things like this.  In particular (untested):
>
> import os.path
>
> for fileName in os.listdir(".")
>if os.path.isfile(fileName) and os.path.splitext(fileName) == "doc":
>filedata = open(fileName)
>xxxdosomething with filedata
>
>
>
> --
>
> DaveA
>
>


-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 10:55 PM, lina  wrote:

> import os.path
>
> tokens=['E']
> result=[]
>
>
> for fileName in os.listdir("."):
> if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
> filedata = open(fileName)
> text=filedata.readlines()
> for line in text:
>
>
> How can I read from line 24 and do further looking for "E".
>
> Thanks,
>
>
The file starts from line 24 is something like

aabbccddEaabb
acbbddEbbaaca
EabcEabc
aEaaEaaa

so for the first column, I can get 1 E, second column is also 1 E, third is
0, four is 2.

namely count the occurence of E in each column.

Thanks,


>
>
> On Thu, Sep 29, 2011 at 10:43 PM, Dave Angel  wrote:
>
>> On 09/29/2011 10:22 AM, lina wrote:
>>
>>> Hi,
>>>
>>> I want to read a bunch of *.doc file in present working directory,
>>>
>>> how can I use for to read one by one and do further work,
>>>
>>> sorry,
>>>
>>> what's the best reference webpage I can use?
>>>
>>> I googled, lots of distracting info, and I barely can understand how they
>>> think.
>>>
>>> THanks,
>>>
>>>  Look in the os module for things like this.  In particular (untested):
>>
>> import os.path
>>
>> for fileName in os.listdir(".")
>>if os.path.isfile(fileName) and os.path.splitext(fileName) == "doc":
>>filedata = open(fileName)
>>xxxdosomething with filedata
>>
>>
>>
>> --
>>
>> DaveA
>>
>>
>
>
> --
> Best Regards,
>
> lina
>
>
>


-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
mport os.path

tokens=['E']
result=[]

for fileName in os.listdir("."):
if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
filedata = open(fileName,'r')
text=filedata.readlines()
for line in text:
print line

why here I print nothing out?

There is .xpm file there with content.

Thanks,

On Thu, Sep 29, 2011 at 11:06 PM, lina  wrote:

>
>
> On Thu, Sep 29, 2011 at 10:55 PM, lina  wrote:
>
>> import os.path
>>
>> tokens=['E']
>> result=[]
>>
>>
>> for fileName in os.listdir("."):
>> if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
>> filedata = open(fileName)
>> text=filedata.readlines()
>> for line in text:
>>
>>
>> How can I read from line 24 and do further looking for "E".
>>
>> Thanks,
>>
>>
> The file starts from line 24 is something like
>
> aabbccddEaabb
> acbbddEbbaaca
> EabcEabc
> aEaaEaaa
>
> so for the first column, I can get 1 E, second column is also 1 E, third is
> 0, four is 2.
>
> namely count the occurence of E in each column.
>
> Thanks,
>
>
>>
>>
>> On Thu, Sep 29, 2011 at 10:43 PM, Dave Angel  wrote:
>>
>>> On 09/29/2011 10:22 AM, lina wrote:
>>>
 Hi,

 I want to read a bunch of *.doc file in present working directory,

 how can I use for to read one by one and do further work,

 sorry,

 what's the best reference webpage I can use?

 I googled, lots of distracting info, and I barely can understand how
 they
 think.

 THanks,

  Look in the os module for things like this.  In particular (untested):
>>>
>>> import os.path
>>>
>>> for fileName in os.listdir(".")
>>>if os.path.isfile(fileName) and os.path.splitext(fileName) == "doc":
>>>filedata = open(fileName)
>>>xxxdosomething with filedata
>>>
>>>
>>>
>>> --
>>>
>>> DaveA
>>>
>>>
>>
>>
>> --
>> Best Regards,
>>
>> lina
>>
>>
>>
>
>
> --
> Best Regards,
>
> lina
>
>
>


-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
On 29 September 2011 16:13, lina  wrote:

> mport os.path
>
> tokens=['E']
> result=[]
>
> for fileName in os.listdir("."):
> if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
> filedata = open(fileName,'r')
>
> text=filedata.readlines()
> for line in text:
> print line
>
> why here I print nothing out?
>
> There is .xpm file there with content.
>
> Thanks,
>
>
Is your .xpm files actually text files?  Or are they binary (e.g. maybe
graphics) files?  (XPM is normally the extension of a graphics filetype.)
Treating a binary file as if its text is not liable to work very well.

Also can you please confirm whether this task is homework/study related?

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 11:18 PM, Walter Prins  wrote:

>
>
> On 29 September 2011 16:13, lina  wrote:
>
>> mport os.path
>>
>> tokens=['E']
>> result=[]
>>
>> for fileName in os.listdir("."):
>> if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
>> filedata = open(fileName,'r')
>>
>> text=filedata.readlines()
>> for line in text:
>> print line
>>
>> why here I print nothing out?
>>
>> There is .xpm file there with content.
>>
>> Thanks,
>>
>>
> Is your .xpm files actually text files?  Or are they binary (e.g. maybe
> graphics) files?  (XPM is normally the extension of a graphics filetype.)
> Treating a binary file as if its text is not liable to work very well.
>
> Also can you please confirm whether this task is homework/study related?
>

I have some awk script to achieve this. I can assure you it's not homework.
LOL ... I have never attended some python course.
sometimes it's hard for you to image how hard I persuade myself to use/think
in python way, forget what is-already-relatively-easy-for-me-to-use bash
script.

the xpm file an read, I just text

f=open('1.xpm','r')
for line in f.readlines():
print line
f.close()

I am google-ing how to get the line index, so will use those after 24.


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


-- 
Best Regards,

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


Re: [Tutor] map one file and print it out following the sequence

2011-09-29 Thread Prasad, Ramit
From: tutor-bounces+ramit.prasad=jpmorgan@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of lina
Sent: Tuesday, September 27, 2011 10:35 PM
Cc: tutor
Subject: Re: [Tutor] map one file and print it out following the sequence

Hi,

Thanks for both of your reply.

File 1 is:

 3 C 1  CUR C19 10.200  12.0110   
 4   CR1 1  CUR C20 1   -0.060  12.0110   
 5HC 1  CUR H20 10.060   1.0080   

File 2 is:
ATOM  2  H20 CUR 1  30.338  28.778  -6.812  1.00  0.00 
ATOM  4  C20 CUR 1  31.394  28.922  -7.039  1.00  0.00
ATOM  5  C19 CUR 1  31.790  29.357  -8.323  1.00  0.00 

I wish to get:

ATOM  5  C19 CUR 1  31.790  29.357  -8.323  1.00  0.00
ATOM  4  C20 CUR 1  31.394  28.922  -7.039  1.00  0.00
ATOM  2  H20 CUR 1  30.338  28.778  -6.812  1.00  0.00   

The dictionary is C19 C20 H20 sequence read from file 1 field 5.
rearrange the file 2 field 3 following the sequence of C19, C20, H20.

Thanks.

===

This is something I wrote *really* quick and is untested. Hopefully someone on 
this list can spot any error I made.

mapping={}
with open("cur.itp") as f:
for line in f.readlines():
parts=line.strip().split()
if len(parts)==8:
   mapping[parts[4]]=parts[0]
with open("processedpdb") as f:
proccessed = [ line.split() for line in f.readlines() ]
processed.sort( key=lambda x: mapping.get( x[2], 0 ) ) # use 0 to put items 
without a mapping at the 
   # top of the file because 
they are probably an error
For line in array:
print ' '.join( line )




Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Dave Angel
(Please don't top-post.  Put your remarks AFTER the part you're quoting 
from the previous message)


On 09/29/2011 10:55 AM, lina wrote:

import os.path

tokens=['E']
result=[]

for fileName in os.listdir("."):
 if os.path.isfile(fileName) and os.path.splitext(fileName)=="xpm":
 filedata = open(fileName)
 text=filedata.readlines()
 for line in text:


How can I read from line 24 and do further looking for "E".

Thanks,




As I said in my earlier message, this was untested.  It gave you the 
building blocks, but was not correct.


In particular, that if-test will always fail, so you're not seeing any 
files.


import os.path

tokens=['E']
result=[]

for fileName in os.listdir("."):

if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm":
filedata = open(fileName)
text=filedata.readlines()
for line in text:
print line


Once you've tested that, then you're ready to just look at line 24.

text is a list, so you can refer to line 24 as text[24]

Or you can get lines 24-28, with  text[24, 29]   (look up slices in the 
Python doc)


==
DaveA


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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 11:28 PM, Dave Angel  wrote:

> (Please don't top-post.  Put your remarks AFTER the part you're quoting
> from the previous message)
>
>
> On 09/29/2011 10:55 AM, lina wrote:
>
>> import os.path
>>
>> tokens=['E']
>> result=[]
>>
>> for fileName in os.listdir("."):
>> if os.path.isfile(fileName) and os.path.splitext(fileName)=="**xpm":
>> filedata = open(fileName)
>> text=filedata.readlines()
>> for line in text:
>>
>>
>> How can I read from line 24 and do further looking for "E".
>>
>> Thanks,
>>
>>
>>
> As I said in my earlier message, this was untested.  It gave you the
> building blocks, but was not correct.
>
> In particular, that if-test will always fail, so you're not seeing any
> files.
>
>
> import os.path
>
> tokens=['E']
> result=[]
>
> for fileName in os.listdir("."):
>
>if os.path.isfile(fileName) and os.path.splitext(fileName)[1]=**
> =".xpm":
>
>filedata = open(fileName)
>text=filedata.readlines()
>for line in text:
>print line
>
>
> Once you've tested that, then you're ready to just look at line 24.
>
> text is a list, so you can refer to line 24 as text[24]
>
> Or you can get lines 24-28, with  text[24, 29]   (look up slices in the
> Python doc)
>

 >>> print splitext.__doc__
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'splitext' is not defined
>>> print slices.__doc__
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'slices' is not defined
>>> print slices._doc_
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'slices' is not defined

Thanks,

>
> ==
> DaveA
>
>
>


-- 
Best Regards,

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


Re: [Tutor] Mac IDE

2011-09-29 Thread Tim Johnson
* Wayne Werner  [110929 03:52]:
> 
> My personal favorite?
> 
> Two terminal windows - one with Vim, editing my Python scripts, and another
> with an interactive interpreter. Since you can map keys in Vim, I have 
> mapped to save and run current file. If you're in the habit of editing
> multiple files you could set it up to map  to ask which file you want to
> set as your main .py file. And since you mentioned debug, I usually just use
> pdb if I need debugging. You could easily map a key such as  to insert a
> new line and type 'pdb.set_trace()'. Vim has a fairly steep learning curve,
> but if you spend 30 minutes with the vimtutor you'll be fine. With newer
> versions of Vim you can also write plugins for them in Python.
 I'll second that. Vim (not vi - more on that later) is my IDE. I
 have customized it using vimscript and what I have is as feature -
 rich as any out-of-the-box IDE - but with differences.

> Of course these capabilities (and many many more) are available with Emacs.

  I used Emacs extensively in the past. Vim is my preference, but
  emacs has a feature that is not present (yet) in vim : the ability
  to run interpreters - as an example the terminal shell and the
  python - asynchronously inside of the application.  This is a very
  handy feature, eliminating the second application window.

> I personally recommend that you learn one (or both) of these editors. They
> will highly improve the speed at which you are able to edit your code.
  I would not wish vim or emacs on anyone who doesn't wish to use
  them. But for someone with an open mind, some points :
  . 'vim' is not 'vi', but is 'descended from' vi.
  . There is 'vim' - teminal mode and 'gvim' - vim with gui.
I use vim as my default midnight command editor, gvim as my
'IDE'
  . Emacs can be run in terminal mode also, with greater speed, but
less features.
  . There are 'easy' modes available for both, enabling a new user to
find themselves in a more familiar environment.
  . The python interpreter can be compiled into vim. On ubuntu it is
the default. This gives the user the ability to customize vim
using python code.
  . Some call emacs and vim 'arcane'. Some ridicule vim's 'modal'
style of editing. Neither are arcane, they are very up to date
and are a parallel way of doing things.
vim modal editing is a thing of beauty. Watching a adept
vim user work can be breathtaking to observe. The corollary
would be that some consider python weird because it is
column-sensitive.

  Just sayin' 
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Prasad, Ramit
Or you can get lines 24-28, with  text[24, 29]   (look up slices in the Python 
doc)

 >>> print splitext.__doc__
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'splitext' is not defined
>>> print slices.__doc__
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'slices' is not defined
>>> print slices._doc_
Traceback (most recent call last):
  File "", line 1, in 
NameError: name 'slices' is not defined


===
I think he meant something like: 
http://docs.python.org/tutorial/introduction.html (see the section on strings 
around half way down) or 
http://docs.python.org/release/2.3.5/whatsnew/section-slices.html



Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi,

On 29 September 2011 16:39, lina  wrote:

>
> Or you can get lines 24-28, with  text[24, 29]   (look up slices in the
>> Python doc)
>>
>
Dave probably meant: text[24:29]



>  >>> print splitext.__doc__
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'splitext' is not defined
> >>> print slices.__doc__
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'slices' is not defined
> >>> print slices._doc_
> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'slices' is not defined
>

You should probably be looking in the documentation, not trying to feed it
into the interpreter.  (If you want to get help on a specific entity in
Python it's usually better to use the "help()" function, e.g:

>>> import os.path
>>> help (os.path.splitext)
Help on function splitext in module ntpath:

splitext(p)
Split the extension from a pathname.

Extension is everything from the last dot to the end, ignoring
leading dots.  Returns "(root, ext)"; ext may be empty.

>>>

Note, trying to do "help(os.path.splitext)" would not have worked before I
imported the "os.path" module.  (Differently put: Whatever you want to get
help() on, must be known to the interpreter, so must either be built in or
previously imported.)

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi,

On 29 September 2011 16:39, lina  wrote:

> Traceback (most recent call last):
>   File "", line 1, in 
> NameError: name 'slices' is not defined
>

Sorry I meant to include a link to relevant documentation:
http://docs.python.org/tutorial/introduction.html

(And apologies for forgetting to remove ther other recipients from the
email.  By the way, a question to the list adminstrators: why does the
default reply to address for this mailing list not default to the mailing
list?  All my other mailing lists operate like that, it's only the Python
list that's peculiar in this way... )

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 11:57 PM, Walter Prins  wrote:

> Hi,
>
> On 29 September 2011 16:39, lina  wrote:
>
>>
>> Or you can get lines 24-28, with  text[24, 29]   (look up slices in the
>>> Python doc)
>>>
>>
> Dave probably meant: text[24:29]
>
>
>
>>  >>> print splitext.__doc__
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> NameError: name 'splitext' is not defined
>> >>> print slices.__doc__
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> NameError: name 'slices' is not defined
>> >>> print slices._doc_
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> NameError: name 'slices' is not defined
>>
>
> You should probably be looking in the documentation, not trying to feed it
> into the interpreter.  (If you want to get help on a specific entity in
> Python it's usually better to use the "help()" function, e.g:
>
> >>> import os.path
> >>> help (os.path.splitext)
> Help on function splitext in module ntpath:
>
> splitext(p)
> Split the extension from a pathname.
>
> Extension is everything from the last dot to the end, ignoring
> leading dots.  Returns "(root, ext)"; ext may be empty.
>
> >>>
>
> Note, trying to do "help(os.path.splitext)" would not have worked before I
> imported the "os.path" module.  (Differently put: Whatever you want to get
> help() on, must be known to the interpreter, so must either be built in or
> previously imported.)
>
> Walter
>
>
> Thanks all for your time,

I found one thing a bit weird, Here is the one:

import os.path

tokens=['E']
result=[]

"""
for fileName in os.listdir("."):
if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm":
"""
filedata = open("1.xpm")
text=filedata.readlines()
for line in text[23]:
print line

1] $ python try2.py | wc -l
206

now changed to:
for line in text[23:24]:
print line

2] $ python try2.py | wc -l
2

for line in text[23:25]:
print line

3] $ python try2.py | wc -l
4

the situation 1 is supposed to be 1, while it's 206, it's just tilted 90
degree of this one line, kind of split. (if I am right here).
2] is correct.
3] is supposed to be 3, right, why it's 4?

and I want to check the correctness before using
for line in text[23:len(text)-1]:
print line

I upload the 1.xpm in below link, really appreciate for the guidance.

https://docs.google.com/leaf?id=0B93SVRfpVVg3NzQxNWU4ZjktNzkwZi00ZDI5LWI1YzAtZTBkZGUzNzJmNGJh&sort=name&layout=list&num=50

-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi,

On 29 September 2011 17:07, lina  wrote:

> I found one thing a bit weird, Here is the one:
>
> import os.path
>
> tokens=['E']
> result=[]
>
> """
> for fileName in os.listdir("."):
> if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm":
> """
> filedata = open("1.xpm")
> text=filedata.readlines()
> for line in text[23]:
> print line
>

> 1] $ python try2.py | wc -l
> 206
>

Please go and carefully study how strings, lists etc work -- you don't seem
to grasp what "text[23]" returns vs what text[23:24] etc returns etc.  To
spell it out:  If the variable text refers to a list of strings, then
text[23] is the 24th string.  24th, because the index starts from 0.
text[23:24] by contrast, is a sublist (called a slice) that contains strings
24 and 25 from the original list.

So, if text[23] is already itself a single string, what can the following
code possibly mean?  Eg in general, what does s[0] give you if s is a
string?  A: The first character in s. So then, what does the following do:

for x in text[23]:
  print x

a: It steps through the letters in text[23] and prints each in turn (on a
new line.)

So what you then do when you "wc -l" text[23], is to effectively count the
number of characters in line 24

You should probably just have run the script without the wc -l and this
would've become very clear very quickly on inspecting the output.   ;)

The other results are similarly explainable, by examining the output. (To be
exact, the lines in the sublists/slices include newline characters.  When
you print them seperately, you therefore end up with more lines than you
think.  Try "print line.strip()" to get rid of the newline.  Try the
following in the python interpreter:

f=open('C:\\Users\\walterp\\Desktop\\1.xpm')
>>> lines=f.readlines()
>>> slice1=lines[23]
>>> slice2=lines[23:24]
>>> slice3=lines[23:25]
>>> print slice1
>>> print slice2
>>> print slice3
>>> print len(slice3)

etc.


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


Re: [Tutor] map one file and print it out following the sequence

2011-09-29 Thread lina
On Thu, Sep 29, 2011 at 10:57 PM, Prasad, Ramit
wrote:

> From: tutor-bounces+ramit.prasad=jpmorgan@python.org [mailto:
> tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of lina
> Sent: Tuesday, September 27, 2011 10:35 PM
> Cc: tutor
> Subject: Re: [Tutor] map one file and print it out following the sequence
>
> Hi,
>
> Thanks for both of your reply.
>
> File 1 is:
>
> 3 C 1  CUR C19 10.200  12.0110
> 4   CR1 1  CUR C20 1   -0.060  12.0110
> 5HC 1  CUR H20 10.060   1.0080
>
> File 2 is:
> ATOM  2  H20 CUR 1  30.338  28.778  -6.812  1.00  0.00
> ATOM  4  C20 CUR 1  31.394  28.922  -7.039  1.00  0.00
> ATOM  5  C19 CUR 1  31.790  29.357  -8.323  1.00  0.00
>
> I wish to get:
>
> ATOM  5  C19 CUR 1  31.790  29.357  -8.323  1.00  0.00
> ATOM  4  C20 CUR 1  31.394  28.922  -7.039  1.00  0.00
> ATOM  2  H20 CUR 1  30.338  28.778  -6.812  1.00  0.00
>
> The dictionary is C19 C20 H20 sequence read from file 1 field 5.
> rearrange the file 2 field 3 following the sequence of C19, C20, H20.
>
> Thanks.
>
> ===
>
> This is something I wrote *really* quick and is untested. Hopefully someone
> on this list can spot any error I made.
>
> mapping={}
> with open("cur.itp") as f:
>for line in f.readlines():
> parts=line.strip().split()
>if len(parts)==8:
>   mapping[parts[4]]=parts[0]
> with open("processedpdb") as f:
>proccessed = [ line.split() for line in f.readlines() ]
> processed.sort( key=lambda x: mapping.get( x[2], 0 ) ) # use 0 to put items
> without a mapping at the
>   # top of the file because
> they are probably an error
> For line in array:
>print ' '.join( line )
>
>
I checked,

::
proAB_processed.pdb
::
ATOM  1  H52 CUR 1  33.502  30.958  -9.831 -0.71 -0.23
H

the output added:

::
proAB_processed.pdb
::

without truly sorting,

but I do think you understand correctly.

Thanks,

>
>
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
>



-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread lina
On Fri, Sep 30, 2011 at 12:31 AM, Walter Prins  wrote:

> Hi,
>
> On 29 September 2011 17:07, lina  wrote:
>
>> I found one thing a bit weird, Here is the one:
>>
>> import os.path
>>
>> tokens=['E']
>> result=[]
>>
>> """
>> for fileName in os.listdir("."):
>> if os.path.isfile(fileName) and os.path.splitext(fileName)[1]==".xpm":
>> """
>> filedata = open("1.xpm")
>> text=filedata.readlines()
>> for line in text[23]:
>> print line
>>
>
>> 1] $ python try2.py | wc -l
>> 206
>>
>
> Please go and carefully study how strings, lists etc work -- you don't seem
> to grasp what "text[23]" returns vs what text[23:24] etc returns etc.  To
> spell it out:  If the variable text refers to a list of strings, then
> text[23] is the 24th string.  24th, because the index starts from 0.
> text[23:24] by contrast, is a sublist (called a slice) that contains strings
> 24 and 25 from the original list.
>
> So, if text[23] is already itself a single string, what can the following
> code possibly mean?  Eg in general, what does s[0] give you if s is a
> string?  A: The first character in s. So then, what does the following do:
>
> for x in text[23]:
>   print x
>
> a: It steps through the letters in text[23] and prints each in turn (on a
> new line.)
>
> So what you then do when you "wc -l" text[23], is to effectively count the
> number of characters in line 24
>
> You should probably just have run the script without the wc -l and this
> would've become very clear very quickly on inspecting the output.   ;)
>
> The other results are similarly explainable, by examining the output. (To
> be exact, the lines in the sublists/slices include newline characters.  When
> you print them seperately, you therefore end up with more lines than you
> think.  Try "print line.strip()" to get rid of the newline.  Try the
> following in the python interpreter:
>
> f=open('C:\\Users\\walterp\\Desktop\\1.xpm')
> >>> lines=f.readlines()
> >>> slice1=lines[23]
> >>> slice2=lines[23:24]
> >>> slice3=lines[23:25]
> >>> print slice1
> >>> print slice2
> >>> print slice3
> >>> print len(slice3)
>

Thanks, I truly understand now. There was a "blank line", and the strip()
works.

(I learned C 10 years ago, but barely used. so can understand something very
basic. Thanks again for your explaination)

Now I am facing how to read each column about the occurence of some letter.

Long time ago, my senior left me a script with the following line,

for line in text:
result.append({t:line.count(t) for t in tokens})

for index,r in enumerate(result):
print(index,"-",r)

I don't understand how it works, kinda of transpose a matrix?




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


-- 
Best Regards,

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Alan Gauld

On 29/09/11 15:22, lina wrote:

I want to read a bunch of *.doc file in present working directory,


What format are the doc files?
If they are word processor files they may well be in binary format so 
you will need to either decode them (using struct?) or find a module 
that can read them, or a tool that can convert them to something you can 
read.


Once you figure out how to read a single file reading multiple files can 
be done in a number of ways including using os.walk() and a

for loop (or the fileinput module).

for root,dirs,files in os.walk(path):
docs = [f for f in files if f.endswith '.doc'] # or use glob
for line in fileinput.input(docs):
#process line


But the hardest bit is likely going to be the reading of the files if 
they are not plain text.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Alan Gauld

On 29/09/11 17:00, Walter Prins wrote:


email.  By the way, a question to the list adminstrators: why does the
default reply to address for this mailing list not default to the
mailing list?


This is an oft debated issue and there are arguments for both options.
The current setup allows easier replies to either originator or list by 
simply selecting which Reply button you use. If you set default reply to 
the list how do you reply to just the originator when you want to?


OTOH if your mail tool doesn't have a ReplyAll button its slightly less 
convenient.


The upshot of all the debates (see the archive!) has been that it is the 
way it was set up so that's the way it is.


> All my other mailing lists operate like that, it's only

the Python list that's peculiar in this way... )


I'm the opposite, all my lists work this way.
I think the older lists tend to work like Python because all the
older list managers (eg listserv etc) tend to work thataway.
With the advent of web mail systems lists seem to be swinging
the other way, but most of my mailing lists pre-date the web
by a long way! :-)


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] Mac IDE

2011-09-29 Thread Alan Gauld

On 29/09/11 12:50, Wayne Werner wrote:


Two terminal windows - one with Vim, editing my Python scripts, and
another with an interactive interpreter

Of course these capabilities (and many many more) are available with Emacs.

I personally recommend that you learn one (or both) of these editors.
They will highly improve the speed at which you are able to edit your code.


Unfortunately vim isn't available by default on MAcOS - at least not the 
last time I looked. They had elvis installed as a "vi".


But Emacs is there in console mode, I think you need to install X to get 
it in GUI mode - in which case you might as well install Emacs for Aqua...


But I haven't used the most recent OS X releases (post Tiger)
(I'm still on a G3 iBook!) so the tool selection may have changed.

Netbeans is another option that works on a Mac. There is
a plugin for Python. From memory this includes an interpreter
window.

Finally, I can also add that the native MacOS developer tools,
including XCode work with Python, but it doesn't include an
integrated interpreter. You need to install/configure XCode
to work with Python, visit the Mac Python pages for details.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

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


Re: [Tutor] map one file and print it out following the sequence

2011-09-29 Thread Prasad, Ramit
>For line in array:
>   print ' '.join( line )

Sorry this it should be:
for line in processed:
   print ' '.join( line )

This worked for me. 
>>> pprint.pprint( processed) # Note in the email I have changed the format but 
>>> not the data
[['ATOM',  '2',  'H20',  'CUR',  '1',  '30.338',  '28.778',  '-6.812',  '1.00', 
 '0.00'], 
 ['ATOM',  '4',  'C20',  'CUR',  '1',  '31.394',  '28.922',  '-7.039',  '1.00', 
 '0.00'],
 ['ATOM',  '5',  'C19',  'CUR',  '1',  '31.790',  '29.357',  '-8.323',  '1.00', 
 '0.00']]
>>> pprint.pprint( sorted( processed, key= lambda x: mapping.get( x[2], 0 ) ) ) 
# I use sorted instead of processed in case it did not sort correctly (that way 
I still have the original list)
[['ATOM',  '5',  'C19',  'CUR',  '1',  '31.790',  '29.357',  '-8.323',  '1.00', 
 '0.00'],
 ['ATOM',  '4',  'C20',  'CUR',  '1',  '31.394',  '28.922',  '-7.039',  '1.00', 
 '0.00'],
 ['ATOM',  '2',  'H20',  'CUR',  '1',  '30.338',  '28.778',  '-6.812',  '1.00', 
 '0.00']]

You should note, that I just used "print" I did not write to file. You will 
need to actually create/open a file, run through the list (e.g. processed) and 
write to the file, and then finally close it.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423


From: tutor-bounces+ramit.prasad=jpmorgan@python.org 
[mailto:tutor-bounces+ramit.prasad=jpmorgan@python.org] On Behalf Of lina
Sent: Thursday, September 29, 2011 11:39 AM
To: tutor
Subject: Re: [Tutor] map one file and print it out following the sequence



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Prasad, Ramit
>This is an oft debated issue and there are arguments for both options.
>The current setup allows easier replies to either originator or list by 
>simply selecting which Reply button you use. If you set default reply to 
>the list how do you reply to just the originator when you want to?

I would have preferred it to set the list as the TO and the originator as the 
reply CC. 
Not sure if that works with the email standards if it just "appears" to work 
that way from Outlook.
That way I can reply by default to the list and if I want to send to the 
originator I can
also do reply all.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423




This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] where to look for python codes

2011-09-29 Thread bodsda
I would suggest looking on http://ubuntuforums.org for the “Beginner 
programming challenges“ - there is an index of past challenges as a sticky in 
the programming talk subforum. A large number of entries for these challenges 
are in python, and as the name implies, the submissions are usually written by 
beginners.

The code will not be enterprise standard, but it should be a good insight into 
how others write python programs

Hope this helps,
Bodsda,
Ubuntu beginners team

P.S: sorry for the top post, smartphone limitation 
Sent from my BlackBerry® wireless device

-Original Message-
From: Praveen Singh 
Sender: tutor-bounces+bodsda=googlemail@python.org
Date: Thu, 29 Sep 2011 13:57:46 
To: 
Subject: [Tutor] where to look for python codes

___
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] Mac IDE

2011-09-29 Thread Robert Johansson
Wing IDE looks promising on my windows machine. I will start by checking out 
their trial under OSX.

Thanks for all suggestions,

Robert
Från: tutor-bounces+robert.johansson=math.umu...@python.org 
[mailto:tutor-bounces+robert.johansson=math.umu...@python.org] För Tom Tucker
Skickat: den 29 september 2011 16:44
Till: Wayne Werner
Kopia: tutor@python.org
Ämne: Re: [Tutor] Mac IDE


Another IDE to consider that supports the MAC OS is PyCharm from JetBrains.
On Thu, Sep 29, 2011 at 7:50 AM, Wayne Werner 
mailto:waynejwer...@gmail.com>> wrote:
On Thu, Sep 29, 2011 at 5:50 AM, Walter Prins 
mailto:wpr...@gmail.com>> wrote:
On 29 September 2011 10:42, Robert Johansson 
mailto:robert.johans...@math.umu.se>> wrote:
Hi,

I know that there is a lot to read about different IDEs on the net but I have 
tried a couple and I'm still not pleased. My demands are not that high, when 
I'm under Windows I'm happy with IDLE (an interactive shell and debug) but the 
problem is with Mac (Python >= 2.7 and OS 10.7). IDLE had serious problems and 
TextWrangler had no interactive shell. There's a lot of other stuff to try and 
I would be grateful if someone could spare me some time on this.


Well, if you're prepared to spend a bit of money, I've heard very good things 
about Wingware, which is also available on Mac  (Note, not a user myself 
currently, but has seen it before and been favourably impressed, enough to 
suggest it here despite not currently actively using it myself.)  Link: 
http://wingware.com/

I'll second that. If you're really into IDEs, Wingware is a great one - they 
also have a student/open source license that may be right up your alley.

My personal favorite?

Two terminal windows - one with Vim, editing my Python scripts, and another 
with an interactive interpreter. Since you can map keys in Vim, I have  
mapped to save and run current file. If you're in the habit of editing multiple 
files you could set it up to map  to ask which file you want to set as your 
main .py file. And since you mentioned debug, I usually just use pdb if I need 
debugging. You could easily map a key such as  to insert a new line and 
type 'pdb.set_trace()'. Vim has a fairly steep learning curve, but if you spend 
30 minutes with the vimtutor you'll be fine. With newer versions of Vim you can 
also write plugins for them in Python.

Of course these capabilities (and many many more) are available with Emacs.

I personally recommend that you learn one (or both) of these editors. They will 
highly improve the speed at which you are able to edit your code.

HTH,
Wayne

___
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] Mac IDE

2011-09-29 Thread Tim Johnson
* Alan Gauld  [110929 09:29]:
> On 29/09/11 12:50, Wayne Werner wrote:
> 
> >Two terminal windows - one with Vim, editing my Python scripts, and
> >another with an interactive interpreter
> >
> >Of course these capabilities (and many many more) are available with Emacs.
> >
> >I personally recommend that you learn one (or both) of these editors.
> >They will highly improve the speed at which you are able to edit your code.
> 
> Unfortunately vim isn't available by default on MAcOS - at least not
> the last time I looked. They had elvis installed as a "vi".
> 
> But Emacs is there in console mode, I think you need to install X to
> get it in GUI mode - in which case you might as well install Emacs
> for Aqua...
 I just got a 2011 mac mini with the last OS ... time doesn't permit
 me to fire it up until tomorrow at the soonest, but I will report
 back on emacs and vim as defaults. A distribution call macvim is
 available and vim can also be custom built.
 cheers
-- 
Tim 
tim at tee jay forty nine dot com or akwebsoft dot com
http://www.akwebsoft.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] a quick Q: how to use for loop to read a series of files with .doc end

2011-09-29 Thread Walter Prins
Hi Alan,

On 29 September 2011 18:12, Alan Gauld  wrote:

> On 29/09/11 17:00, Walter Prins wrote:
>
>  email.  By the way, a question to the list adminstrators: why does the
>> default reply to address for this mailing list not default to the
>> mailing list?
>>
>
> This is an oft debated issue and there are arguments for both options.
> The current setup allows easier replies to either originator or list by
> simply selecting which Reply button you use. If you set default reply to the
> list how do you reply to just the originator when you want to?
>

Well, for that particular (comparatively rare) case, with copy and paste.
(Which is in any case basically what I have to remember to do each and every
time I reply to the list-only currently, assuming I've also remembered to
click reply-all instead of reply...)

IMHO, ideally things should work exactly as they are except that "Reply"
goes to the list, "Reply-all" sends to the list as well as anyone else
(which then allows copying and pasting/re-arranging of addresses etc if only
some people are meant to get the response.) As I say, this would be
consistent with how most other mailing lists (that I'm on anyway) works.
IMHO the current default behaviour makes the most common use-case more work
than it would otherwise be, but fine, if the powers that be actually want it
like it is, then who am I to argue. :)


>
>
> > All my other mailing lists operate like that, it's only
>
>> the Python list that's peculiar in this way... )
>>
>
> I'm the opposite, all my lists work this way.
> I think the older lists tend to work like Python because all the
> older list managers (eg listserv etc) tend to work thataway.
> With the advent of web mail systems lists seem to be swinging
> the other way, but most of my mailing lists pre-date the web
> by a long way! :-)


Yes... well I don't want to start an argument, but I can't help but point
out that just because things might've in sometimes in the past been set up
to work like that doesn't mean it's neccesarily the most appropriate way it
should be done today, in general, or on this list in particular.

But, as I say, I don't want to start an argument -- if this has been debated
before (and you've just told me it has), and so has been deliberately and
intentionally set to the current behaviour then that's fine.  I'll not say
another word about it.  :) (I'll however reserve the right to have a few
choice thoughts about it next time I again forget to swap around the
addresses on reply-all, or when I again robotically click reply instead of
reply-all when responding to this list and end up sending a reply to the
person only instead of to the list and then have to go dig the reply out the
sent box again and forward it on to the list manually...  ;) )

Best,

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


[Tutor] Mailing list archive oddity?

2011-09-29 Thread Prasad, Ramit
So I wanted to reference a post I had already deleted and I looked at the 
archive (http://mail.python.org/pipermail/tutor/). 

My question...how do I get a future capable email client like the archive? :)

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423



This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mailing list archive oddity?

2011-09-29 Thread Devin Jeanpierre
> So I wanted to reference a post I had already deleted and I looked at the 
> archive (http://mail.python.org/pipermail/tutor/).
>
> My question...how do I get a future capable email client like the archive? :)

What mail client do you use? Does it offer a way to move posts out of
the inbox, without deleting them?

That's what I do, but I use gmail.

Devin

On Thu, Sep 29, 2011 at 3:55 PM, Prasad, Ramit
 wrote:
> So I wanted to reference a post I had already deleted and I looked at the 
> archive (http://mail.python.org/pipermail/tutor/).
>
> My question...how do I get a future capable email client like the archive? :)
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
>
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
> ___
> 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] Mailing list archive oddity?

2011-09-29 Thread Prasad, Ramit
-Original Message-
From: Devin Jeanpierre [mailto:jeanpierr...@gmail.com] 
Sent: Thursday, September 29, 2011 3:11 PM
To: Prasad, Ramit
Cc: tutor@python.org
Subject: Re: [Tutor] Mailing list archive oddity?

> So I wanted to reference a post I had already deleted and I looked at the 
> archive (http://mail.python.org/pipermail/tutor/).
>
> My question...how do I get a future capable email client like the archive? :)

What mail client do you use? Does it offer a way to move posts out of
the inbox, without deleting them?

That's what I do, but I use gmail.

Devin

--

I think you misunderstood my question. The web archive of the list has a few 
entries that have not occurred yet (which you may have noticed if you visited 
the link).

January 2027:   [ Thread ] [ Subject ] [ Author ] [ Date ]  [ Gzip'd Text 
597 bytes ]
November 2012:  [ Thread ] [ Subject ] [ Author ] [ Date ]  [ Gzip'd Text 2 
KB ]

I was asking (facetiously) if there was an email client that could receive 
email from the future. I am curious to how this happened, but I am not sure 
anyone on this list is a list administrator and would know.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423




This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mailing list archive oddity?

2011-09-29 Thread Devin Jeanpierre
> I think you misunderstood my question. The web archive of the list has a few 
> entries that have not occurred yet (which you may have noticed if you visited 
> the link).

Ah. I have an unfortunate medical condition where I only click
hyperlinks when they don't matter.

Devin

On Thu, Sep 29, 2011 at 4:25 PM, Prasad, Ramit
 wrote:
> -Original Message-
> From: Devin Jeanpierre [mailto:jeanpierr...@gmail.com]
> Sent: Thursday, September 29, 2011 3:11 PM
> To: Prasad, Ramit
> Cc: tutor@python.org
> Subject: Re: [Tutor] Mailing list archive oddity?
>
>> So I wanted to reference a post I had already deleted and I looked at the 
>> archive (http://mail.python.org/pipermail/tutor/).
>>
>> My question...how do I get a future capable email client like the archive? :)
>
> What mail client do you use? Does it offer a way to move posts out of
> the inbox, without deleting them?
>
> That's what I do, but I use gmail.
>
> Devin
>
> --
>
> I think you misunderstood my question. The web archive of the list has a few 
> entries that have not occurred yet (which you may have noticed if you visited 
> the link).
>
> January 2027:   [ Thread ] [ Subject ] [ Author ] [ Date ]      [ Gzip'd Text 
> 597 bytes ]
> November 2012:  [ Thread ] [ Subject ] [ Author ] [ Date ]      [ Gzip'd Text 
> 2 KB ]
>
> I was asking (facetiously) if there was an email client that could receive 
> email from the future. I am curious to how this happened, but I am not sure 
> anyone on this list is a list administrator and would know.
>
> Ramit
>
>
> Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
> 712 Main Street | Houston, TX 77002
> work phone: 713 - 216 - 5423
>
>
>
>
> This email is confidential and subject to important disclaimers and
> conditions including on offers for the purchase or sale of
> securities, accuracy and completeness of information, viruses,
> confidentiality, legal privilege, and legal entity disclaimers,
> available at http://www.jpmorgan.com/pages/disclosures/email.
> ___
> 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] Mailing list archive oddity?

2011-09-29 Thread Hugo Arts
On Thu, Sep 29, 2011 at 10:25 PM, Prasad, Ramit
 wrote:
>
> I think you misunderstood my question. The web archive of the list has a few 
> entries that have not occurred yet (which you may have noticed if you visited 
> the link).
>
> January 2027:   [ Thread ] [ Subject ] [ Author ] [ Date ]      [ Gzip'd Text 
> 597 bytes ]
> November 2012:  [ Thread ] [ Subject ] [ Author ] [ Date ]      [ Gzip'd Text 
> 2 KB ]
>
> I was asking (facetiously) if there was an email client that could receive 
> email from the future. I am curious to how this happened, but I am not sure 
> anyone on this list is a list administrator and would know.
>
> Ramit
>

In fact, every e-mail client is technically capable of receiving
messages from the future! Unfortunately, there are as of this writing
no clients that can send messages into the past :(

The archives go by the date header found in the e-mail. This is
supposed to indicate the time that the e-mail was sent. So we are left
with two options:

* someone from the future is in need of python help and is sending
messages back in time.
* someone has their system clock set wrong.

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


Re: [Tutor] Mailing list archive oddity?

2011-09-29 Thread Mac Ryan
On Thu, 29 Sep 2011 23:08:19 +0200
Hugo Arts  wrote:

> * someone from the future is in need of python help and is sending
> messages back in time.

I told Guido that Python version 5.2 sucked, but he wouldn't /
will not listen! :-/

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


Re: [Tutor] Mailing list archive oddity?

2011-09-29 Thread Terry Carroll

On Thu, 29 Sep 2011, Hugo Arts wrote:


* someone from the future is in need of python help and is sending
messages back in time.


I'm betting this is Guido and his time machine again.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Mac IDE

2011-09-29 Thread Fernando Salamero
Another great IDE is NINJA-IDE, http://www.ninja-ide.org , but they are still 
searching for somebody who makes an installer. Any volunteer?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor