Re: [Tutor] Looking for a tutor to review my code and provideconstructive feedback.

2010-11-05 Thread Mark Tolonen


Glen Clark gle...@gmail.com wrote in message 
news:aanlktimabbj8ae35q3ao9+xzbvtnyzbz3wrudahmn...@mail.gmail.com...

Hello,

I have completed my first python script. This is after watching a video
guide on python and is my first attempt at writing code in python. While 
the
code is not very useful I got the idea for it when googling python 
projects

for beginners.

The idea was to create a script that asked the user to input a list of 
names

and allow the user to change a name if he wanted before confirming the
entries.

I tried to incorporate what I had learnt from the videos, such as
conditionals, error handling, functions etc... and write it how I would
write code in future.

Please if you are kind enougth to take the time to provide feedback I 
would

appreciate that it is constructive :)

The script is here: http://bpaste.net/show/10658/


Your code is very readable...more so than some experienced people ;^)

A few suggestions (and assuming Python 3.X, since that's what it looks 
like):


  * list shadows a built-in type, and should not be used for variable 
names.  names would be more appropriate.

  * input() return a string, so no need for str(input(...)).
  * range(x) is equivalent to range(0,x).
  * The two loops in InitiateEntries can be consolidated:

   for In in range(NumItems):
   names.append(input(Enter name {}: .format(In+1)))

   Or using a list comprehension:

   names = [input(Enter name {}: .format(In+1) for In in 
range(NumItems)]


   * Prefer for name in names: instead of using indexing, or for 
idx,name in enumerate(names): if indexes are needed.  Example:


   for idx,name in enumerate(names):
   print({}: {}.format(idx,name)

   * Since 1-based indexing was used elsewhere to present names to the 
user, the PrintEntries display code should also use idx+1.

   * When returning a boolean value, you can simpify:

   if confirmed == 'n':
   return True
   else:
   return False

   To:

   return confirmed == 'n'

Also see PEP8 (http://www.python.org/dev/peps/pep-0008/) for Python's 
suggested coding standard.


-Mark


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


[Tutor] Fw: rights

2010-11-05 Thread ALAN GAULD
fowarding to group, please use reply-all when replying.

 
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/




- Forwarded Message 
 From: Chris King g.nius...@gmail.com
 To: Alan Gauld alan.ga...@btinternet.com
 Sent: Friday, 5 November, 2010 0:48:51
 Subject: Re: [Tutor] rights
 
 On 11/1/2010 8:43 PM, Alan Gauld wrote:
  
  Chris King g.nius...@gmail.com wrote
  
  You give the user account executing the script rights to read  the folder.
  
  HTH,
  
   It was a folder on my desktop, which I can always read, right, and 
  destroy. 
I  ran it on that user.
  
  In that case we probably need to  see:
  
  1) What OS?
  
  2) What does the code look  like?
  
  3) How are you running it?
  
  4) What error  messages do you get?
  
  Also, is it a folder you are trying to  read or a file?
  They are not the same.
  
  
 I'm trying  to get the raw binary of a file in linux or windows.
 When I run:
 
 f =  open('C:/Documents and Settings/family/Desktop/Tuxpaint', 'rb')
 
 in  Windows, it raises:
 
 Traceback (most recent call last):
   File  pyshell#1, line 1, in module
 f =  open('C:/Documents and Settings/family/Desktop/Tuxpaint', 'rb')
 IOError:  [Errno 13] Permission denied: 'C:/Documents and  
Settings/family/Desktop/Tuxpaint'
 
 Can you help?
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] argparse: how to use the returned Namespace object?

2010-11-05 Thread Mac Ryan
On Fri, 2010-11-05 at 01:11 +, Walter Prins wrote:
 You need to distinguish between what __dict__ *is*, and what it
 *contains*.  dir() does introspection, it inspects what an object in
 Python *is*, e.g. displays all the methods and attributes of the
 object.  It does not however know anything about what (if anything)
 the object might contain, in the data storage sense. [...]

Thank you Walter, now I got it. :)

Mac.

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


[Tutor] querying the name of a calling python file

2010-11-05 Thread Garry Willgoose
For a while now I have been using the command below in a python file to 
determine the name of the python file that I use to launch an application 
(i.e.IF I go 'python junk.py' I want to get 'junk.py'). The command I have use 
that I came across somewhere some time ago was

sys.modules['__main__'].__dict__['__file__']

Now this works fine for the standard python interpretter but when I use ipython 
(I'm using the enthought distribution 6.1) this command returns

/Library/Frameworks/Python.framework/Versions/6.1/lib/python2.6/site-packages/IPython/FakeModule.py

I discovered this when  I was tracking down inconsistencies/errors between the 
matplotlib in the enthought distribution depending on whether you use python or 
ipython. My question is this: Is the way I'm getting the file name the 
recommended way or did I pick up a bit of flaky advice? 

I'm puzzled by the matplot lib errors (the y axes on imgshow() show problems in 
python but appear to 1st order to be OK in ipython) ... but I'll pursue that at 
the Matplotlib, enthought and ipython forums once I've been able to run a 
broader cross-section of my codes. 



Prof Garry Willgoose,
Australian Professorial Fellow in Environmental Engineering,
Director, Centre for Climate Impact Management (C2IM),
School of Engineering, The University of Newcastle,
Callaghan, 2308
Australia.

Centre webpage: www.c2im.org.au

Phone: (International) +61 2 4921 6050 (Tues-Fri AM); +61 2 6545 9574 (Fri 
PM-Mon)
FAX: (International) +61 2 4921 6991 (Uni); +61 2 6545 9574 (personal and 
Telluric)
Env. Engg. Secretary: (International) +61 2 4921 6042

email:  garry.willgo...@newcastle.edu.au; g.willgo...@telluricresearch.com
email-for-life: garry.willgo...@alum.mit.edu
personal webpage: www.telluricresearch.com/garry

Do not go where the path may lead, go instead where there is no path and leave 
a trail
  Ralph Waldo Emerson






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


Re: [Tutor] querying the name of a calling python file

2010-11-05 Thread शंतनू

On 05-Nov-2010, at 4:45 PM, Garry Willgoose wrote:

 For a while now I have been using the command below in a python file to 
 determine the name of the python file that I use to launch an application 
 (i.e.IF I go 'python junk.py' I want to get 'junk.py'). The command I have 
 use that I came across somewhere some time ago was
 
 sys.modules['__main__'].__dict__['__file__']
 
 Now this works fine for the standard python interpretter but when I use 
 ipython (I'm using the enthought distribution 6.1) this command returns
 
 /Library/Frameworks/Python.framework/Versions/6.1/lib/python2.6/site-packages/IPython/FakeModule.py
 
 I discovered this when  I was tracking down inconsistencies/errors between 
 the matplotlib in the enthought distribution depending on whether you use 
 python or ipython. My question is this: Is the way I'm getting the file name 
 the recommended way or did I pick up a bit of flaky advice? 
 
 I'm puzzled by the matplot lib errors (the y axes on imgshow() show problems 
 in python but appear to 1st order to be OK in ipython) ... but I'll pursue 
 that at the Matplotlib, enthought and ipython forums once I've been able to 
 run a broader cross-section of my codes. 
 

Try the following code:

===
#!/usr/bin/env python
import sys
print sys.argv
===

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


Re: [Tutor] Looking for a tutor to review my code and provideconstructive feedback.

2010-11-05 Thread Glen Clark
*#Your code is very readable...more so than some experienced people ;^)*

Thank you, that is very motivating that I am at least on the right track!

#A few suggestions (and assuming Python 3.X, since that's what it looks
like):

Yeah it is 3.1, forgot to mention that.

# * list shadows a built-in type, and should not be used for variable
names.  names would be more appropriate.

I used list as it was a list and therefore new what argument to pass. I did
not even consider that this would be confusing! Thank you for pointing it
out.

# * input() return a string, so no need for str(input(...)).
# * range(x) is equivalent to range(0,x).

Thank you, I will note these for future code :)

#* The two loops in InitiateEntries can be consolidated:

Thank you, Seems a much better way or doing it.

#* Prefer for name in names: instead of using indexing, or for idx,name
in enumerate(names): if indexes are needed.  Example:
# * Since 1-based indexing was used elsewhere to present names to the user,
the PrintEntries display code should also use idx+1

I thought that by using an index would be an easy way for the user to select
which element of the list to edit. Not seem the enumerate keyword before so
I will look up what that does :)

 .
#  * When returning a boolean value, you can simpify:

Ah, thank you!

Really useful feedback, I will note the points highlighted for my next
mini-project. I feel it is important that I am writing proper code before
moving onto learning modules and such.



On 5 November 2010 08:32, Mark Tolonen
metolone+gm...@gmail.commetolone%2bgm...@gmail.com
 wrote:


 Glen Clark gle...@gmail.com wrote in message
 news:aanlktimabbj8ae35q3ao9+xzbvtnyzbz3wrudahmn...@mail.gmail.com...

  Hello,

 I have completed my first python script. This is after watching a video
 guide on python and is my first attempt at writing code in python. While
 the
 code is not very useful I got the idea for it when googling python
 projects
 for beginners.

 The idea was to create a script that asked the user to input a list of
 names
 and allow the user to change a name if he wanted before confirming the
 entries.

 I tried to incorporate what I had learnt from the videos, such as
 conditionals, error handling, functions etc... and write it how I would
 write code in future.

 Please if you are kind enougth to take the time to provide feedback I
 would
 appreciate that it is constructive :)

 The script is here: http://bpaste.net/show/10658/


 Your code is very readable...more so than some experienced people ;^)

 A few suggestions (and assuming Python 3.X, since that's what it looks
 like):

  * list shadows a built-in type, and should not be used for variable
 names.  names would be more appropriate.
  * input() return a string, so no need for str(input(...)).
  * range(x) is equivalent to range(0,x).
  * The two loops in InitiateEntries can be consolidated:

   for In in range(NumItems):
   names.append(input(Enter name {}: .format(In+1)))

   Or using a list comprehension:

   names = [input(Enter name {}: .format(In+1) for In in
 range(NumItems)]

   * Prefer for name in names: instead of using indexing, or for idx,name
 in enumerate(names): if indexes are needed.  Example:

   for idx,name in enumerate(names):
   print({}: {}.format(idx,name)

   * Since 1-based indexing was used elsewhere to present names to the user,
 the PrintEntries display code should also use idx+1.
   * When returning a boolean value, you can simpify:

   if confirmed == 'n':
   return True
   else:
   return False

   To:

   return confirmed == 'n'

 Also see PEP8 (http://www.python.org/dev/peps/pep-0008/) for Python's
 suggested coding standard.

 -Mark



 ___
 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] Looking for a tutor to review my code and provide constructive feedback.

2010-11-05 Thread Glen Clark
Thank you very much for the feedback Luke. I have taken it onboard. I
especially like the .lower().strip()[0] method ^^

Regards,
G

On 4 November 2010 22:38, Luke Paireepinart rabidpoob...@gmail.com wrote:

 Also for your confirm entries read about sentinel values for while loops.
 It saves you repeating the conditional in the loop body. And you might want
 to .lower().strip()[0] the input choice so that they can use y, Y, yes, or
 whatever. Remember, users suck at generating accurate and correct input so
 don't give them any credit you can avoid.


 -
 Sent from a mobile device with a bad e-mail client.
 -

 On Nov 4, 2010, at 3:10 PM, Glen Clark gle...@gmail.com wrote:

 Hello,

 I have completed my first python script. This is after watching a video
 guide on python and is my first attempt at writing code in python. While the
 code is not very useful I got the idea for it when googling python projects
 for beginners.

 The idea was to create a script that asked the user to input a list of
 names and allow the user to change a name if he wanted before confirming the
 entries.

 I tried to incorporate what I had learnt from the videos, such as
 conditionals, error handling, functions etc... and write it how I would
 write code in future.

 Please if you are kind enougth to take the time to provide feedback I would
 appreciate that it is constructive :)

 The script is here: http://bpaste.net/show/10658/
 http://bpaste.net/show/10658/

 ___

 Tutor maillist  -   Tutor@python.orgTutor@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] Server

2010-11-05 Thread Chris King

 On 11/4/2010 9:46 PM, Corey Richardson wrote:



On 11/4/2010 8:43 PM, Chris King wrote:

 Dear Tutors,
May server and client programs aren't working. They basically 
simplify socket and SocketServer. Run them directly to test them. 
They do work locally. They don't work from one computer to the next 
on the same network. Please Help.


Sincerely,
Me, Myself, and I

P.S. How to you stop a server loop and open up the port?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

When ever I have worked on network, it's always been a firewall issue. 
If you are using Windows, turn off the built-in firewall. That's what 
fixed my problems.

Hope it helped,
~Corey

make sure you click reply to all, so you don't just send it to me
also, it is on the same network, so the server shouldn't be a problem
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Displaying picture and Text Downloads

2010-11-05 Thread Patty
I just realized I did the same thing - must have hit reply to one instead of 
reply to all :}


I had a followup question for you all - and would like to know the answer to 
Alan's question about print quality - below -


Patty

- Original Message - 
From: Patty pa...@cruzio.com

To: Alan Gauld alan.ga...@btinternet.com
Sent: Thursday, November 04, 2010 11:14 AM
Subject: Re: [Tutor] Displaying picture and Text


Yes, I would like to know this, I want this function to be really modular 
and I thought of something else.  If my solution turns out to be using 
Tkinter functions only then wouldn't that mean I downloaded and am 
'import'ing the Image library for nothing?


This might mean the second addon library I download the source and 
documentation for.  So how are people keeping their customized system 
organized?  I could come up with all sorts of scenarios of losing track of 
libraries, having too many you never use, and doc you never use, etc.


Patty

- Original Message - 
From: Alan Gauld alan.ga...@btinternet.com

To: tutor@python.org
Sent: Thursday, November 04, 2010 10:39 AM
Subject: Re: [Tutor] Displaying picture and Text




Alan Gauld alan.ga...@btinternet.com wrote

fhdl = Image.open(C:\Users\StarShip\PyProgs\\bbsparkle.gif)
fhdl.show()



The Tkinter PhotoImage object can display jpg. I can't recall if
it does gifs.


Sorry I got that wrong, it can display gifs but not jpgs (despite the 
fact that jpgs are used more often for photos than gifs!) So you will 
need to convert the jpg to a gif - which might lose a lot of quality!


Anyone know of a way to get decent quality in a Tkinter image?
Is there any support in PIL itself?

Alan G.


___
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] Server

2010-11-05 Thread Alan Gauld


Chris King g.nius...@gmail.com wrote

If you are using Windows, turn off the built-in firewall. That's 
what fixed my problems.

~Corey


also, it is on the same network, so the server shouldn't be a 
problem


I think Corey means the firewall on your PC if you have one. It could
be blocking outgoing traffic to uncommon port numbers or somesuch.

Its worth trying if only to eliminate the possibility

Alan G. 



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


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Alan Gauld


Terry Carroll carr...@tjc.com wrote


On Windows, I do something along the lines of this:

  startpoint=D:/
  for (root, dirs, files) in os.walk(startpoint):
 (stuff)

What would I use for startpoint in Linux?  


I don't use Ubuntu so don;t know the standard anmswer 
there but it will depend on where the CD is mounterd.


I usually mount cdroms on /dev/cdrom

But I don't use a standdard distro so set up the mount 
myself (based on where I did itr when I had a Sun 
workstation!).


If you have access to the Linux box can you use a 
file mamnager type program to see where it is mounted?


Alan G.

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


Re: [Tutor] Displaying picture and Text Downloads

2010-11-05 Thread Alan Gauld


Patty pa...@cruzio.com wrote

I had a followup question for you all - and would like to know the 
answer to Alan's question about print quality - below -



A Google search led me to this page which seems to offer a solution
using PIL anmd a module called ImageTk:

http://codeidol.com/python/python3/A-Tkinter-Tour,-Part-1/Viewing-and-Processing-Images-with-PIL/

I've never tried it so I'll be interested to hear if it works for 
you...


Alan G., 



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


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Steven D'Aprano

Alan Gauld wrote:

I don't use Ubuntu so don;t know the standard anmswer there but it will 
depend on where the CD is mounterd.


I usually mount cdroms on /dev/cdrom


Surely that's where you mount cdroms *from*? I can't think that using 
/dev/cdrom as the mount point would be a good idea!


Anyway, more modern Linux systems automatically mount CDs and DVDs. By 
convention, /mnt/... is used for manually mounts, and /media/... for 
automatic mounts of media.




--
Steven

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


[Tutor] Hi

2010-11-05 Thread Luke Pettit
Hi everyone,
I'm just about to begin to learn python and have bookmarked a number of
sites to learn from
http://www.alan-g.me.uk/ is the main one but after reading this

On Nov 4, 2010, at 3:10 PM, Glen Clark gle...@gmail.com wrote:

Hello,

I have completed my first python script. This is after watching a video
guide on python and is my first attempt at writing code in python. While the
code is not very useful I got the idea for it when googling python projects
for beginners.


I was interested in which video tutorials Glen was watching, and if anyone
else could recommend some video tutorials to watch, mainly because of a mild
dyslexia and preference for video tutorials.

I have been learning Autodesk 3d Studio Max
http://south-apac.autodesk.com/adsk/servlet/pc/index?siteID=1157326id=15474303
for
several years and learning it's scripting language Maxscript
http://rosettacode.org/wiki/Category:MAXScript and since Autodesk now own
all the competitors software and they all (except Max) use Python for
their coding I thought it would be the way to go when learning a new
language. Blender also uses Python btw.

My 3d site http://lukepettit-3d.blogspot.com/

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


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Terry Carroll

On Sat, 6 Nov 2010, Steven D'Aprano wrote:

Anyway, more modern Linux systems automatically mount CDs and DVDs. By 
convention, /mnt/... is used for manually mounts, and /media/... for 
automatic mounts of media.


I am seeing my volume in /media ; however, I won't know the volume name 
when my program runs.  I can't use whatever shows up in /media, because 
there could be more than one drive.

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


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Steven D'Aprano

Terry Carroll wrote:
I have a program that traverses the directory of a CDROM using os.walk. 
I do most of my work on Windows, but some on (Ubuntu) Linux, and I'd 
like this to work in both environments.


On Windows, I do something along the lines of this:

  startpoint=D:/


What if the user has two CD drives? What if they have a second hard disk 
mounted on D:/, and a network drive on E:/, and use F:/ or A:/ or Z:/ 
for the CD drive?


If this program is for you, then it is fine to make assumptions about 
where the CD drive will be mounted, but don't make the mistake of 
thinking that they're not assumptions.




  for (root, dirs, files) in os.walk(startpoint):
 (stuff)

What would I use for startpoint in Linux?  I've tried /dev/sr0 and 
/dev/sr0/; neither work.  (If I recall correctly, the for-loop just 
drops through; I'm not at my Linux box right now to confirm.)


As a general rule, don't touch anything in /dev unless you know what 
you're doing. /dev/sr0, and it's more user-friendly name /dev/cdrom, are 
devices, not folders. This is how low-level programs get access to the 
raw bytes being read from the device (in this case the CDROM drive) 
*before* it is turned into files.



A number of other mount points (like /dev/cdrom, I think) are links to 
/dev/sr0; and don't work either.


No, of course not. If they're links, that will mean that they are 
essentially nicknames or aliases. If Fred Smith doesn't respond when you 
talk to him, then calling him Freddy, Mr Smith, Hey you! or Frederick 
isn't going to work either.


It *does* work to start at /media/VOLUMENAME, where VOLUMENAME is the 
volume ID of the disc; but my program will not know that.  I need to be 
able to do this without knowing the volume name.


Yes, this is because you need to look at the mount point. The mount 
point is where the CDROM disk is mounted as a file system, in other 
words, where you can see the files on the disk *as files*. If you want 
to read the raw bytes off the disk, you open /dev/cdrom as a file and 
read from it.


On Unix and Linux systems, there are two conventions for mounting 
external media. One is that if you, the user, mount something by hand 
using the mount command, it gets placed in /mnt (old-school Unix sys 
admins had keyboards without vowels *wink*). Often people would use 
subdirectories under /mnt:


/mnt/cdrom
/mnt/floppy

are the two most common ones.

The other convention is that modern window/desktop managers like KDE and 
Gnome will automatically mount devices by name under /media. This is 
typically for CDs, DVDs, cameras and mobile phones with file storage, 
USB sticks and portable hard drives, etc.


If you only have one CD drive, and no other devices mounted, you can 
just look at /media and walk over that without caring what the CD drive 
is called. In other words, just use /media as the starting point, and 
let os.walk discover the name of the CD under it.


But if you might have an external hard drive plugged in, or a USB key, 
or similar, then you need to find out what the volume name of the 
mounted CD drive is. That's a good question and I don't have an answer 
right now. Let me think about it and get back to you.



--
Steven

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


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Steven D'Aprano

Steven D'Aprano wrote:

But if you might have an external hard drive plugged in, or a USB key, 
or similar, then you need to find out what the volume name of the 
mounted CD drive is. That's a good question and I don't have an answer 
right now. Let me think about it and get back to you.


Well that was easy. You need to query the external tool volname, which 
should be present on just about any Linux system.


Use the subprocess module to call volname /dev/cdrom.


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


Re: [Tutor] Looking for a tutor to review my code and provide constructive feedback.

2010-11-05 Thread Walter Prins
One final suggestion to add to the others: Install and use both pylint, and
pychecker.  That will help ensure you don't make silly errors or omissions
and follow a consistent coding style that matches the generally accepted
format well.

PyLint: http://pypi.python.org/pypi/pylint
PyChecker: http://pypi.python.org/pypi/PyChecker/0.8.12

Aside: The easiest way to install these (and many other) Python modules is
using Pip: http://pypi.python.org/pypi/pip/0.8.1

Using Pip, installing pylint is just the following command:

pip install pylint

Likewise for pychecker.

Have a good weekend.

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


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Terry Carroll

On Sat, 6 Nov 2010, Steven D'Aprano wrote:


Terry Carroll wrote:
I have a program that traverses the directory of a CDROM using os.walk. I 
do most of my work on Windows, but some on (Ubuntu) Linux, and I'd like 
this to work in both environments.


On Windows, I do something along the lines of this:

  startpoint=D:/


What if the user has two CD drives? What if they have a second hard disk 
mounted on D:/, and a network drive on E:/, and use F:/ or A:/ or Z:/ for the 
CD drive?



D:/ doesn't enter into it.  That's on Windows, I'm asking about Linux.  I 
used D:/ to show a single example of what works on Windows to explain 
what I am looking for on Linux.


In practice, the drive specification will be coming from a config file. 
It would be D:? on some systems, E:/ on others or maybe both.


But my question is not about Windows, which I already have covered.  My 
question is, to put it succinctly:


How can one use os.walk to walk a directory structure of a CDROM on LInux 
when the volume name is not known?


On Unix and Linux systems, there are two conventions for mounting external 
media. One is that if you, the user, mount something by hand using the 
mount command, it gets placed in /mnt (old-school Unix sys admins had


keyboards without vowels *wink*). Often people would use subdirectories under 
/mnt:


/mnt/cdrom
/mnt/floppy

are the two most common ones.


No such luck:

t...@vraspberry:~$ ls -pal /mnt
total 8
drwxr-xr-x  2 root root 4096 2010-04-23 03:23 ./
drwxr-xr-x 23 root root 4096 2010-10-04 10:42 ../

t...@vraspberry:~$ ls -pal /mnt/cdrom
ls: cannot access /mnt/cdrom: No such file or directory
t...@vraspberry:~$ ls -pal /mnt/floppy
ls: cannot access /mnt/floppy: No such file or directory


The other convention is that modern window/desktop managers like KDE and 
Gnome will automatically mount devices by name under /media.


Yes, I mentioned this, but it requires knowing the volume name.

If you only have one CD drive, and no other devices mounted, you can 
just look at /media and walk over that without caring what the CD drive 
is called. In other words, just use /media as the starting point, and 
let os.walk discover the name of the CD under it.


But that has the same problem I already mentioned in the prior note: what 
if there's more than one device?  The same thing you pointed out above 
about D:/




Well that was easy. You need to query the external tool volname, which
should be present on just about any Linux system.

Use the subprocess module to call volname /dev/cdrom.


Aha, this looks like it will work; I was starting to think along these 
lines; I was thinking of reading the output of df, but this is cleaner.


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


Re: [Tutor] Reading the CDROM in Linux

2010-11-05 Thread Carlos Daniel Ruvalcaba Valenzuela
This is more of a Linux question, but here is some advice:

All files under /dev are more or less raw representations of the
devices, meaning that /dev/cdrom or /dev/sr0 files represent the CDROM
devices, however this is for raw access to the device data, now really
for normal use, the sistem may mount this device in another place
(like inside the /media directory), so that a directory will represent
the contents (filesystem) of the device, which is what you may want to
use.

In the example that you are using, you may call 'df' from python and
parse the data, which more or less is presented in the following
format: device, space, used space, mounted directory. What you need
the the directory where the device is mounted (the last data), and
then you may use walk on that, taking care that the directory is under
your media directory so that you won't walk the root directory
entirely (your hard disk).

You may want to use os.popen or one of the many process modules to
call 'df', then parse each line by spliting the spaces or tabs, then
the rest is more or less what you are doing right now.

Regards,
Carlos Ruvalcaba

On Fri, Nov 5, 2010 at 5:59 PM, Terry Carroll carr...@tjc.com wrote:
 Alan Gauld wrote:

 I don't use Ubuntu so don;t know the standard anmswer
 there but it will depend on where the CD is mounterd.

 I usually mount cdroms on /dev/cdrom

 That's what I figured; I now realize I didn't say so in my email, but it's
 mounted at /dev/sr0, which is where I came up with that mount point.


  t...@vraspberry:~$ df
  . . .

  /dev/sr0               614350    614350         0 100% /media/MP_04_074


 MP_04_074 is the volume name.

 But in python:

 import os
 for (r, d, f) in os.walk(/dev/sr0): print r, d, f

 ...

 for (r, d, f) in os.walk(/dev/sr0/): print r, d, f

 ...

 for (r, d, f) in os.walk(/dev/cdrom/): print r, d, f

 ...

 for (r, d, f) in os.walk(/dev/cdrom): print r, d, f

 ...

 for (r, d, f) in os.walk(/dev/cdrom0): print r, d, f

 ...

 for (r, d, f) in os.walk(/dev/cdrom0/): print r, d, f

 ...


 None of those work; but:


 for (r, d, f) in os.walk(/media/MP_04_074): print r, d, f

 ...
 /media/MP_04_074 ['directory1'] []
 (etc.)


 What I can't figure out is how to do this if my program does not know the
 volume name.  I won't know the colume name in advance, and in fact, I'll be
 processing one CDROM, replacing it and processing another, etc.
 ___
 Tutor maillist  -  tu...@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] test

2010-11-05 Thread Danyelle Davis
im wondering if im able to mail this list.  I sent an email asking for good
newbie projects but never saw it post.  All i got was the welcome/ info
email.

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


Re: [Tutor] test

2010-11-05 Thread Luke Paireepinart
You don't get your own e-mails back.

On Fri, Nov 5, 2010 at 11:37 PM, Danyelle Davis ladyni...@gmail.com wrote:
 im wondering if im able to mail this list.  I sent an email asking for good
 newbie projects but never saw it post.  All i got was the welcome/ info
 email.
 LN
 ___
 Tutor maillist  -  tu...@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] Displaying Pictures Text

2010-11-05 Thread Patty
Hi Alan - 

I tried using ImageTk from the PIL library to display jpegs (and hopefully any 
picture type)  instead of just gif as you suggested below.  I read online that 
these these types of programs should 
be run from executables not in the interpreter but it crashes and I can't read 
the error.  Here is the program:

import Image
import ImageTk

fhdl = Image.open(C:\Users\StarShip\PyProgs\SuitGirl.jpg)
ImageTk.PhotoImage(fhdl)

Tested in interpreter and get the following error.  I included Image.show() to 
be 
sure pic could be displayed and it did come up in HP Photo Viewer just like the 
gif file did
and I tried the PhotoImage() after I got the cursor back

Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type help, copyright, credits or license for more information.
 import Image
 import ImageTk
 fhdl = Image.open(C:\Users\StarShip\PyProgs\SuitGirl.jpg)
 fhdl.show()
 ImageTk.PhotoImage(fhdl)
Traceback (most recent call last):
  File stdin, line 1, in module
  File C:\Python26\lib\site-packages\PIL\ImageTk.py, line 113, in __init__
self.__photo = apply(Tkinter.PhotoImage, (), kw)
  File C:\Python26\lib\lib-tk\Tkinter.py, line 3285, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
  File C:\Python26\lib\lib-tk\Tkinter.py, line 3226, in __init__
raise RuntimeError, 'Too early to create image'
RuntimeError: Too early to create image


 

Alan Gauld alan.ga...@btinternet.com wrote in message 
news:ib270l$p3...@dough.gmane.org...
 
 Patty pa...@cruzio.com wrote
 
 I had a followup question for you all - and would like to know the 
 answer to Alan's question about print quality - below -
 
 
 A Google search led me to this page which seems to offer a solution
 using PIL anmd a module called ImageTk:
 
 http://codeidol.com/python/python3/A-Tkinter-Tour,-Part-1/Viewing-and-Processing-Images-with-PIL/
 
 I've never tried it so I'll be interested to hear if it works for 
 you...
 
 Alan G., 
 
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] test

2010-11-05 Thread Steven D'Aprano

Luke Paireepinart wrote:

You don't get your own e-mails back.


I do.

Perhaps it's an option when you sign up?



--
Steven

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


Re: [Tutor] Programs for Newbies?

2010-11-05 Thread Steven D'Aprano

Danyelle Davis wrote:

Hi all,

Any suggestions for a newbie to program while learning python?  I am new to
programming and python.



What are you interested in?

Interested in maths? Write a program to generate prime numbers, or to 
search for amicable numbers. Look at Project Euler, although (in my 
opinion) the puzzles there are quite hard are require a lot of maths 
know-how.


Write a number guessing game. Or Hangman or Battleship.

Try the Python Challenge:
http://www.pythonchallenge.com/


More puzzle sites here, written in other languages but you can solve 
them in Python if you like:


http://sixrevisions.com/resources/10-puzzle-websites-to-sharpen-your-programming-skills/


Unfortunately, most of them seem to be aimed at people who aren't 
newbies. I think the world needs a good set of programming puzzles for 
beginners.



Good luck!


--
Steven

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


Re: [Tutor] Programs for Newbies?

2010-11-05 Thread Steven D'Aprano

Danyelle Davis wrote:

Hi all,

Any suggestions for a newbie to program while learning python?  I am new to
programming and python.



Here's a few suggestions:


Write a program that asks the user to enter a word, then counts how many 
vowels and consonants are in the word.


Write a program that asks the user for a list of numbers, separated by 
spaces or commas, and then calculated the average.


A program that prints the time.

A program that prints how many days to go until their next birthday.

A program that counts how many palindrome numbers there are between two 
other numbers. (A palindrome number is one like 12321, or 473374.)


A program that sings (well, prints) the There were ten in the bed 
song. If you don't know it, it is a children's song. You start off by 
holding up ten fingers, or you can use actual children. You don't have 
to start with ten. Then you sing:


There were ten in the bed, and the little one said,
Roll over! Roll over!
And they all rolled over and ONE FELL OUT!
There were nine in the bed, and the little one said,
Roll over! Roll over!
And they all rolled over and ONE FELL OUT!
There were eight in the bed, and the little one said,
...

Well you get the idea. Eventually you've left with only the little one 
left, and the song ends:


There was one in a bed, and the little one said
Good night!




--
Steven

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