Re: [Tutor] Regular Expressions: escaping in character classes/character sets

2008-07-07 Thread Kent Johnson
On Mon, Jul 7, 2008 at 1:44 AM, Josh Rosen <[EMAIL PROTECTED]> wrote:
> I was browsing through the source code of Django when I found the following
> regular expression:
>
> tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')
>
> Shouldn't this be
> functionally equivalent to the much more readable:
>
> tspecials = re.compile(r'[ ()<>@,;:\\"/\[\]?=]')

Yes, I think so. Try it and see!

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] New to pythong

2008-07-07 Thread Jeremiah Stack





Hello everybody:

I am new to this mailing list, and it said that i could the simplest of 
questions. So i was wondering if anyone could be so kind as to e-mail me a 
project idea or something to go out an learn to do in python. I don't know any 
languages, but i am definitely not computer illiterate. i have read so many 
tutorial about getting started but so far that is where the tutorial have left 
me ( how to print  "Hello World") and such. 

Any ideas great thanks.



_
Making the world a better place one message at a time.
http://www.imtalkathon.com/?source=EML_WLH_Talkathon_BetterPlace___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] search path

2008-07-07 Thread Jerry Hill
On Sun, Jul 6, 2008 at 3:47 PM, Robert Johansson
<[EMAIL PROTECTED]> wrote:
> Running the script file she gets error messages claiming that the textfiles
> cannot be found when they are to be opened with
> fileid=file('textfilename.txt','r') even though the same thing works fine on
> my system. Anyone how knows what the cause of this is?

Are you sure the filename is correct?  As I understand it, Window's
filesystems are case insensitive, so 'textfilename.txt' would also
work for files named 'TextFileName.txt', or 'textfilename.TXT', etc.
I believe the Mac's filesystem is case sensitive, so all of those
names would be different files, and could in fact all reside in the
same directory together.

-- 
Jerry
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread W W
A quick google search for "Python tutorial" will yeild several results.

I recommend "Think Python" -  http://greenteapress.com/thinkpython/

HTH,
Wayne

On Mon, Jul 7, 2008 at 11:40 AM, Jeremiah Stack <[EMAIL PROTECTED]> wrote:
>
>
> Hello everybody:
>
> I am new to this mailing list, and it said that i could the simplest of
> questions. So i was wondering if anyone could be so kind as to e-mail me a
> project idea or something to go out an learn to do in python. I don't know
> any languages, but i am definitely not computer illiterate. i have read so
> many tutorial about getting started but so far that is where the tutorial
> have left me ( how to print  "Hello World") and such.
>
> Any ideas great thanks.
>
>
>
> 
> Making the world a better place one message at a time. Check out the i'm
> Talkathon.
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>



-- 
To be considered stupid and to be told so is more painful than being
called gluttonous, mendacious, violent, lascivious, lazy, cowardly:
every weakness, every vice, has found its defenders, its rhetoric, its
ennoblement and exaltation, but stupidity hasn't. - Primo Levi
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] graphs & diagrams in python

2008-07-07 Thread Monika Jisswel
>
> I have done well with matplotlib.
>

Thanks for the large options, I went for matplotlib too as I liked it more
than the other options, & also with my later readings I realized it was the
best. Later I will update this discussion with some examples I used.


2008/7/7 Kent Johnson <[EMAIL PROTECTED]>:

> On Sat, Jul 5, 2008 at 9:16 AM, Kent Johnson <[EMAIL PROTECTED]> wrote:
> > On Fri, Jul 4, 2008 at 3:54 PM, Monika Jisswel
> > <[EMAIL PROTECTED]> wrote:
> >> Hi Again,
> >>
> >> What is the best library for drawing graphs & diagrams to ilustrate some
> >> statistics ?
> >
> > A few possibilities here:
> > http://wiki.python.org/moin/GraphicsAndImages
>
> Here is a longer list of plotting and visualization tools:
> http://code.enthought.com/chaco/
> http://gnuplot-py.sourceforge.net/
> http://newcenturycomputers.net/projects/gdmodule.html
> http://www.slac.stanford.edu/grp/ek/hippodraw/
> http://mayavi.sourceforge.net/index.html
> http://home.gna.org/pychart/
> http://www.pyngl.ucar.edu/
> http://www.tarind.com/depgraph.html
> https://svn.enthought.com/enthought/wiki/TVTK
> http://vpython.org/
> http://pyqwt.sourceforge.net/home.html
> http://home.gna.org/veusz/
> http://www.dislin.de/
> http://oss.oetiker.ch/rrdtool/
>
> I have done well with matplotlib.
> Kent
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread Monika Jisswel
you can start with stuff you need like,  for example write a program that
scans your hard disk & tells you the details about pdf, jpg, zip, avi files
that you have, with creation date and sizes.
when you need help write us.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread Marc Tompkins
On Mon, Jul 7, 2008 at 9:40 AM, Jeremiah Stack <[EMAIL PROTECTED]> wrote:

>
>
> Hello everybody:
>
> I am new to this mailing list, and it said that i could the simplest of
> questions. So i was wondering if anyone could be so kind as to e-mail me a
> project idea or something to go out an learn to do in python. I don't know
> any languages, but i am definitely not computer illiterate. i have read so
> many tutorial about getting started but so far that is where the tutorial
> have left me ( how to print  "Hello World") and such.
>
> Any ideas great thanks.
>
>
First of all, I mean no offense to the OP.  However, this question comes up
a lot on this list, and it always bugs me.  People decide they want to learn
Python, and then ask strangers to give them a reason to do it.  I may be
totally wrong about this, but it doesn't seem like a good way to learn
_anything_, let alone a programming language.  The most important element
for success is enthusiasm, and how can you generate any enthusiasm working
on somebody else's homework project?  Unless you learn best under external
discipline, in which case I suggest you take a class...

My advice to all potential Pythonistas who want to learn on their own: think
of a problem you need to solve, or a cool game you've wanted to implement,
or a tool you want but don't have.  In my own case, I had a project I needed
to do (printing mailing labels from records in an old proprietary database)
that was going to suck if I used only the tools I already had.  I'd been
wanting to get into Python, and I decided to use Python to do the job and
learn as I went.  It was WONDERFUL, and I've been in love with Python ever
since.  (Yes, I've used it for fun stuff since then, but my first experience
was of Python saving me hours and hours of pain.)

If you don't have a professional task that you could apply Python to, just
look around your environment for a day or so looking for problems to solve.
(My favorite example of this, although it's a very silly program and written
in JavaScript besides, is Roast Beef's "Eggs and Milk Minder" from
Achewood.)


Just my €0.0075...

-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] file object in memory

2008-07-07 Thread Monika Jisswel
I didn't know about tempfile.NamedTemporaryFile ! looks nice because you
don't care about the file anymore, you just use it.
another solution could be to wrap the data (that is each line in the file
still in memory) into mysql statements such as 'insert into table  (aa,
bb, cc) values ( 11, 22, 33)' & pipe it to mysql directly, it will be slow
for tasks like a load but i don't deal with more than 4000 per time & thats
every 15 Minutes.


2008/7/7 Martin Walsh <[EMAIL PROTECTED]>:

> Monika Jisswel wrote:
> > You know bob, you are very clever, I have used RAM disk for realtime
> > recording of audio before but it never occured to me to use it for light
> > jobs like this one, I just compeletely ignored it as an option & by the
> > way this openes a lot of doors for many of my other programs.
> >
> > but wouldn't it be very nice if there  was a way of creating a file
> > object inside python ? something like :
> > myfile = mkfile('some_string')
> > & we're done ?
>
> If I understand what you're after, perhaps tempfile.NamedTemporaryFile
> is close. Granted it creates a 'real' file, subject to filesystem
> performance, but it is automatically deleted when closed.
>
> ---
>
> Also, while I wouldn't recommend it, I thought it might be worth
> mentioning that you can specify a named pipe (or fifo) with mysql 'load
> data' -- although this may be limited to *nix or Mac, I'm not sure.
>
> It is a tricky dance since, IIUC, the mysql process has to open the
> named pipe for reading before you can write to it, else the write will
> block waiting for a reader and your program will hang. My first thought
> would be to spawn a subprocess of the mysql client, or mysqlimport, to
> start the read, then write data to the named pipe. Something like the
> following (untested):
>
> ...
>
> fifoname = '/tmp/mysql.fifo'
> if os.path.exists(fifoname):
>os.remove(fifoname)
> os.mkfifo(fifoname)
>
> sql = """\
> "load data local infile '%s' into table statistics
>fields terminated by '\\t' lines terminated by '\\n';"
> """ % fifoname
>
> conninfo[sql] = sql
> mysqlcmd = \
>  'mysql %(dbname)s -h %(host)s -u %(user)s -e %(sql)s' % conninfo
>
> mysqlp = sp.Popen(mysqlcmd, stdout=sp.PIPE, shell=True)
>
> # should be ready to write
> fifofp = file(fifoname, 'w')
> p1 = sp.Popen(somecmd1, stdout=fifofp, shell=True)
> fifofp.close()
>
> mysqlp.wait()
>
> ...
>
> Seems like an awful lot of work, for questionable gain. I would use a
> regular file. If you're concerned about performance, Bob's ramdisk
> suggestion seems more appropriate.
>
> HTH,
> Marty
>
> >
> >
> > I don't think there is a pure Pythonic way. Have you considered
> > using a RamDisk? http://en.wikipedia.org/wiki/RAM_disk for general
> > details.
> >
> >
> http://www.codeguru.com/cpp/w-p/system/devicedriverdevelopment/article.php/c5789/
> > for a Windows Ram Disk driver installer. I just tried it - it works
> > like a charm.
> >
> > HTH.
> >
> > --
> > Bob Gailer
> > 919-636-4239 Chapel Hill, NC
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] New to Python

2008-07-07 Thread Robert Berman





Wayne,

What he says he is looking for is a programming challenge.
Unfortunately, the fact that he feels he is not "computer  illiterate" 
does not tell us what he does know and what he needs to spend
considerable time learning. 



Jerry, 

There is a web page called "Challenge-You" set up for novice to
advanced novice to learn and to hone already learned skills. It is
generic enough for any language. There are some Lisp devotees working
through the problems. My comfortable language is C++, but I have been
playing with Python for almost 3 weeks  and I am loving it. Remember
this, GOOGLE is your friend. This news group is for when you can't find
what you need on Google. Below is a relatively simple challenge I think
you should use to sharpen your Python teeth (skills if you prefer). 



**


Using the Fibonacci numbers (starting at 1), the prime numbers (starting at 2), and the positive integers (starting at 1), the product of the correlating values would look like this:





F(i) * P(i) * I(i) = 1*2*1, 1*3*2, 2*5*3, 3*7*4, ...





Find the sum of the first 100 correlating products.





(in the example of 4 above, the answer would be 122)


**



I am assuming your math background has already acquainted you with both
Fibonacci series and Prime series. If not, or you need to review, check
out Wikipedia. Write a well structured plan to solve the problem. Then
use Google, and the excellent tutorial suggested by Wayne to began
defining the python methodologies to build your lists. Feel free to ask
questions as you go, but please, please, do not start with "I'm
stumped." Show us what you've done, suggest what you think should
happen, and ask, if you can, very specific questions about very
specific problems you are having. You will be amazed at the quality of help you will
get from this group as long as you are willing to show what you have accomplished.

Best of luck.

Robert Berman



W W wrote:

  A quick google search for "Python tutorial" will yeild several results.

I recommend "Think Python" -  http://greenteapress.com/thinkpython/

HTH,
Wayne

On Mon, Jul 7, 2008 at 11:40 AM, Jeremiah Stack <[EMAIL PROTECTED]> wrote:
  
  
Hello everybody:

I am new to this mailing list, and it said that i could the simplest of
questions. So i was wondering if anyone could be so kind as to e-mail me a
project idea or something to go out an learn to do in python. I don't know
any languages, but i am definitely not computer illiterate. i have read so
many tutorial about getting started but so far that is where the tutorial
have left me ( how to print  "Hello World") and such.

Any ideas great thanks.




Making the world a better place one message at a time. Check out the i'm
Talkathon.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor



  
  


  




___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread Alan Gauld

"Marc Tompkins" <[EMAIL PROTECTED]> wrote

First of all, I mean no offense to the OP.  However, this question 
comes up
a lot on this list, and it always bugs me.  People decide they want 
to learn

Python, and then ask strangers to give them a reason to do it.


I know what you mean Marc but I don't think these beginners
are asking for a reason - they want to know how to programme.
They know that programmers can do all sorts of cool things
with computers. But the bsaic tutorials don't usually teach
you enough to know where to even start on wruiting a new
GUI based application or game. So where do you go after
you learn the basics? Remember these are often complete
beginners who have never used any kind of programming
language before. Its like learning the scales on a piano,
now how do I learn a tune?

My advice to all potential Pythonistas who want to learn on their 
own: think
of a problem you need to solve, or a cool game you've wanted to 
implement,

or a tool you want but don't have.


I agree this is best. Provided the expectation level is kept in check.
For example if someone decided to write a WYSIWYG desktop
publishing programme as a first step after doing my tutor they would
very soon get discouraged and give up. But if they took a simple
home brewed lay-out language and translated it into HTML, maybe
based on CSS stylesheets then its probably within their grasp.


In my own case, I had a project I needed to do (printing mailing
labels from records in an old proprietary database)
that was going to suck if I used only the tools I already had.


And that' a good exercise. But a beginner usually isn't even
sure if Python could tackle such a project or where to start.

If you don't have a professional task that you could apply Python 
to, just
look around your environment for a day or so looking for problems to 
solve.


Again good advice if you have even a basic idea of what programming
can achieve. But you need that concept first. It' one reason that 
overly
basic or overly theoretical programming tutorials can lead to 
problems.

Its also why in my tutor I provide several suggested projects and
enhancements to the examples I give. Plus I try to introduce the
practical elements into the examples I give rather than using,
for example, purely math based ones. (And yes I know most math
problems have practical applications, but not for most amateurs!)

In the meantime lets encourage these beginners to think up their
own problems but at the same time give them ideas as for typical
tasks that are within their reach.

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread Nick Scholtes
Thanks for the info on the Think Python book, and thanks Jeremiah, for
posing this question. That book is one of the best Python learning resources
I've yet found! Makes it really easy to understand!

Nick


On Mon, Jul 7, 2008 at 12:43 PM, Marc Tompkins <[EMAIL PROTECTED]>
wrote:

> On Mon, Jul 7, 2008 at 9:40 AM, Jeremiah Stack <[EMAIL PROTECTED]>
> wrote:
>
>>
>>
>> Hello everybody:
>>
>> I am new to this mailing list, and it said that i could the simplest of
>> questions. So i was wondering if anyone could be so kind as to e-mail me a
>> project idea or something to go out an learn to do in python. I don't know
>> any languages, but i am definitely not computer illiterate. i have read so
>> many tutorial about getting started but so far that is where the tutorial
>> have left me ( how to print  "Hello World") and such.
>>
>> Any ideas great thanks.
>>
>>
> First of all, I mean no offense to the OP.  However, this question comes up
> a lot on this list, and it always bugs me.  People decide they want to learn
> Python, and then ask strangers to give them a reason to do it.  I may be
> totally wrong about this, but it doesn't seem like a good way to learn
> _anything_, let alone a programming language.  The most important element
> for success is enthusiasm, and how can you generate any enthusiasm working
> on somebody else's homework project?  Unless you learn best under external
> discipline, in which case I suggest you take a class...
>
> My advice to all potential Pythonistas who want to learn on their own:
> think of a problem you need to solve, or a cool game you've wanted to
> implement, or a tool you want but don't have.  In my own case, I had a
> project I needed to do (printing mailing labels from records in an old
> proprietary database) that was going to suck if I used only the tools I
> already had.  I'd been wanting to get into Python, and I decided to use
> Python to do the job and learn as I went.  It was WONDERFUL, and I've been
> in love with Python ever since.  (Yes, I've used it for fun stuff since
> then, but my first experience was of Python saving me hours and hours of
> pain.)
>
> If you don't have a professional task that you could apply Python to, just
> look around your environment for a day or so looking for problems to solve.
> (My favorite example of this, although it's a very silly program and written
> in JavaScript besides, is Roast Beef's "Eggs and Milk Minder" from
> Achewood .)
>
> Just my €0.0075...
>
> --
> www.fsrtechnologies.com
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Art: bellsoffreedom.cgsociety.org/gallery/

Blog: cognitivealchemy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread bhaaluu
On Mon, Jul 7, 2008 at 12:40 PM, Jeremiah Stack <[EMAIL PROTECTED]> wrote:
>
>
> Hello everybody:
>
> I am new to this mailing list, and it said that i could the simplest of
> questions. So i was wondering if anyone could be so kind as to e-mail me a
> project idea or something to go out an learn to do in python. I don't know
> any languages, but i am definitely not computer illiterate. i have read so
> many tutorial about getting started but so far that is where the tutorial
> have left me ( how to print  "Hello World") and such.
>
> Any ideas great thanks.
>

Hi J

Take a look at this stuff:
The book is old, based on ancient line-numbered BASIC.

I started out trying to learn about Text Adventure Games.

So the 'project' is to make the games described in the book
run in Python. There are five games. I got the first three
working, and started on the fourth, then got busy with
other things. However, you can read the book, take apart
the source code I've done, put it back together, modify it,
whatever. It's a fun beginner project, if you're interested
in Text Adventure Games.

http://www.geocities.com/ek.bhaaluu/python/index.html

Happy Programming!
-- 
b h a a l u u at g m a i l dot c o m
In a world without fences, who needs Gates?
Kid on Bus: What are you gonna do today, Napoleon?
Napoleon Dynamite: Whatever I feel like I wanna do. Gosh!
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread FT

Hi!


Yes, Mark had something to say, and so did Alan. Games are a good start, 
also a home need, or a business need. 
The way I started Python was games. The Yhatzee game, then my Star Trek 
game, converted over from the original basic game. Then the battleship game, 
the board game, which required people to call out grid places to see if a ship 
was hit...
Since I am visually impaired, and sounds are all I need, then the first 
games are all sound effects and voices. Then the need for a sighted person to 
understand, then the visual, buttons and menu's come in. Then the rest is your 
imagination.

For when learning each level of python a new need arises. I solved the 
event issue I raised last by playing with the details of events, understanding 
what is needed, and reading the formats and playing with them to see the 
results. Many commands, just select which works best.

For when writing python programs you must understand the dictionary and 
list formats. They come in handy. As does the list comprehension idea and it's 
format.

Many things to try and do. Just have to come up with a need, or fun. The 
rest of the imagination is yours.

Just remember that at first the program is large, bulky, then once other 
formats and commands are learned, the program gets smaller, then larger to fit 
more options, then smaller...

Think of a game to play and then expand on it.

Bruce




Thanks for the info on the Think Python book, and thanks Jeremiah, for posing 
this question. That book is one of the best Python learning resources I've yet 
found! Makes it really easy to understand!

Nick



On Mon, Jul 7, 2008 at 12:43 PM, Marc Tompkins <[EMAIL PROTECTED]> wrote:

  On Mon, Jul 7, 2008 at 9:40 AM, Jeremiah Stack <[EMAIL PROTECTED]> wrote:



Hello everybody:

I am new to this mailing list, and it said that i could the simplest of 
questions. So i was wondering if anyone could be so kind as to e-mail me a 
project idea or something to go out an learn to do in python. I don't know any 
languages, but i am definitely not computer illiterate. i have read so many 
tutorial about getting started but so far that is where the tutorial have left 
me ( how to print  "Hello World") and such. 

Any ideas great thanks.



  First of all, I mean no offense to the OP.  However, this question comes up a 
lot on this list, and it always bugs me.  People decide they want to learn 
Python, and then ask strangers to give them a reason to do it.  I may be 
totally wrong about this, but it doesn't seem like a good way to learn 
_anything_, let alone a programming language.  The most important element for 
success is enthusiasm, and how can you generate any enthusiasm working on 
somebody else's homework project?  Unless you learn best under external 
discipline, in which case I suggest you take a class...

  My advice to all potential Pythonistas who want to learn on their own: think 
of a problem you need to solve, or a cool game you've wanted to implement, or a 
tool you want but don't have.  In my own case, I had a project I needed to do 
(printing mailing labels from records in an old proprietary database) that was 
going to suck if I used only the tools I already had.  I'd been wanting to get 
into Python, and I decided to use Python to do the job and learn as I went.  It 
was WONDERFUL, and I've been in love with Python ever since.  (Yes, I've used 
it for fun stuff since then, but my first experience was of Python saving me 
hours and hours of pain.)

  If you don't have a professional task that you could apply Python to, just 
look around your environment for a day or so looking for problems to solve.  
(My favorite example of this, although it's a very silly program and written in 
JavaScript besides, is Roast Beef's "Eggs and Milk Minder" from Achewood.)  

  Just my €0.0075...


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to python(g)=python" g=(embarrassing)

2008-07-07 Thread Jeremiah Stack
Hey

I want to thank you all for your patience, suggestions, constructive  
criticism, and idea  builders!
I now have good thoughts to start, i will now try some of the suggested 
tutorials and activities.
For me before the sugestions the turorials were like reading the sentence "the 
tree is tall and black" without knowing what tree, tall, and black are or why i 
needed to know that. 
Now i have a goal in mind something i think will be neat to work for. Hopefully 
now i will be able to pick up the concepts.

No programming background, working on my math along with my degree. imberising 

Thanks everyone

(i don't know if I'm supposed to say thank you as that might get redundant)



Date: Mon, 7 Jul 2008 17:33:37 +
From: [EMAIL PROTECTED]
To: tutor@python.org
Subject: Re: [Tutor] New to pythong

you can start with stuff you need like,  for example write a program that scans 
your hard disk & tells you the details about pdf, jpg, zip, avi files that you 
have, with creation date and sizes.
when you need help write us.




_
The i’m Talkaton. Can 30-days of conversation change the world?
http://www.imtalkathon.com/?source=EML_WLH_Talkathon_ChangeWorld___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to pythong

2008-07-07 Thread FT

Hello everybody:

I am new to this mailing list, and it said that i could the simplest of 
questions. So i was wondering if anyone could be so kind as to e-mail me a 
project idea or something to go out an learn to do in python. I don't know any 
languages, but i am definitely not computer illiterate. i have read so many 
tutorial about getting started but so far that is where the tutorial have left 
me ( how to print  "Hello World") and such. 

Any ideas great thanks.

Hi!

Someone posted the description on how to fid and list files. This is one 
you could look at, study, and then expand on it. I added the file search as 
well.

In each module you can expand and do much more with it, but when dealing 
with files and directories you must remember that you can erase a lot of stuff 
if you're not careful.


Enjoy, Bruce



import sys, os   # imports all the functions in the os module (operating system 
functions)
cwd = os.getcwd()   # gets the current working directory and places it in the 
variable cwd
print "Enter file to search for: "
file2find = str(raw_input("__>"))
if file2find=="":
sys.exit()
dirFiles = open( "filelist.txt","w")  # creates the file filelist.txt ready for 
writing using the variable dirFiles
# the walk function returns the current directory in root, the directories in 
dirs
# and the files in root in files. By using the for loop it traverses every 
folder
# from the starting folder.
c=0  #Count the files found!
for root, dirs, files in os.walk(cwd):
#dirFiles.write(root + "\n")   # writes to dirFiles.txt the current 
directory name
i=0   #file count for directory to save directory path if found!
for theFiles in files:  # will iterate all the files in the current 
directory
if file2find in theFiles:
i+=1
c+=1
if i==1:
dirFiles.write(root + "\n")   # writes to dirFiles.txt the 
current directory name
dirFiles.write( "___ " + theFiles + "\n") # writes the 
filename to dirlist.txt. the
dirFiles.close() # Cleanly saves and closes the file dirlist.txt
# Note: the "\n" in the write lines adds the newline character so that the next 
write starts on a newline



import sys, os   # imports all the functions in the os module (operating system 
functions)
cwd = os.getcwd()   # gets the current working directory and places it in the 
variable cwd
print "Enter file to search for: "
file2find = str(raw_input("__>"))
if file2find=="":
sys.exit()
dirFiles = open( "filelist.txt","w")  # creates the file filelist.txt ready for 
writing using the variable dirFiles
# the walk function returns the current directory in root, the directories in 
dirs
# and the files in root in files. By using the for loop it traverses every 
folder
# from the starting folder.
c=0  #Count the files found!
for root, dirs, files in os.walk(cwd):
#dirFiles.write(root + "\n")   # writes to dirFiles.txt the current 
directory name
i=0   #file count for directory to save directory path if found!
for theFiles in files:  # will iterate all the files in the current 
directory
if file2find in theFiles:
i+=1
c+=1
if i==1:
dirFiles.write(root + "\n")   # writes to dirFiles.txt the 
current directory name
dirFiles.write( "___ " + theFiles + "\n") # writes the 
filename to dirlist.txt. the
dirFiles.close() # Cleanly saves and closes the file dirlist.txt
# Note: the "\n" in the write lines adds the newline character so that the next 
write starts on a newline

import os   # imports all the functions in the os module (operating system 
functions)
cwd = os.getcwd()   # gets the current working directory and places it in the 
variable cwd
dirFiles = open( "dirlist.txt","w")  # creates the file dirlist.txt ready for 
writing using the variable myfiles
# the walk function returns the current directory in root, the directories in 
dirs
# and the files in root in files. By using the for loop it traverses every 
folder
# from the starting folder.
for root, dirs, files in os.walk(cwd):
dirFiles.write(root + "\n")   # writes to dirlist.txt the current directory 
name
for theFiles in files:  # will iterate all the files in the current 
directory
dirFiles.write( "___ " + theFiles + "\n") # writes the filename 
to dirlist.txt. the
dirFiles.close() # Cleanly saves and closes the file dirlist.txt
# Note: the "\n" in the write lines adds the newline character so that the next 
write starts on a newline
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to python(g)=python" g=(embarrassing)

2008-07-07 Thread Marc Tompkins
I did wonder whether there was a joke there...  is the Pythong the hot new
trend in beachwear?

On a creepier note, if you make the mistake of going to python dot com
instead of dot org, a Pythong is the least of your worries...  eeewww.
-- 
www.fsrtechnologies.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] New to python(g)=python" g=(embarrassing)

2008-07-07 Thread Nick Scholtes
Thank you so much for that horrendous imagery. I think I'll go learn C#
instead.   : )

Nick



On Mon, Jul 7, 2008 at 3:28 PM, Marc Tompkins <[EMAIL PROTECTED]>
wrote:

> I did wonder whether there was a joke there...  is the Pythong the hot new
> trend in beachwear?
>
> On a creepier note, if you make the mistake of going to python dot com
> instead of dot org, a Pythong is the least of your worries...  eeewww.
> --
> www.fsrtechnologies.com
> ___
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>


-- 
Art: bellsoffreedom.cgsociety.org/gallery/

Blog: cognitivealchemy.blogspot.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] While loop counter

2008-07-07 Thread David

Hi, I am trying to get a while loop that will execute 5 time then stop.

#!/usr/bin/python
# Filename myfirstclass.py
#
# A Little digital clock

from time_class import Time
import sys
import time

mytime = Time()

print "Can you tell me the time (24h)?"
hour = input("Give the hour: ")
minute = input("Give the minutes: ")
second = input("Give the seconds: ")

mytime.set_time(hour, minute, second)
#counter = 0
#while counter < 5 :
#counter = counter + 1
while True:
   mytime.tick()
   mytime.print_time()
   time.sleep(1) # Sleep for 1 second
counter = 0
while counter < 5 :
   counter = counter + 1

Here is the class;

#!/usr/bin/python
# Filename: time_class.py

class Time:

   def __init__(self):
   self.__hour = 0
   self.__minute = 0
   self.__second = 0

   def set_time(self, hour, minute, second):
   self.set_hour(hour)
   self.set_minute(minute)
   self.set_second(second)

   def set_hour(self, hour):
   if 0 <= hour and hour < 24:
   self.__hour = hour

   def set_minute(self, minute):
   if 0 <= minute and minute < 60:
 self.__minute = minute
  
   def set_second(self, second):

   if 0 <= second and second < 60:
   self.__second = second

   def tick(self):
   self.__second += 1
   self.__minute += self.__second / 60
   self.__hour += self.__minute / 60
  
   self.__hour = self.__hour % 24

   self.__minute = self.__minute % 60
   self.__second = self.__second % 60
  
  
   def print_time(self):

   print '%02d:%02d:%02d' % (self.__hour, self.__minute, self.__second)

Thanks, very new to Python.
-david

--
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While loop counter

2008-07-07 Thread John Fouhy
On 08/07/2008, David <[EMAIL PROTECTED]> wrote:
> Hi, I am trying to get a while loop that will execute 5 time then stop.

Hi David,

The standard pattern is like this:

i = 0
while i < 5:
# the stuff you want to do goes here
i = i + 1

Note that if you know exactly how many times you will execute your
loop, you should use a for loop instead:

for i in range(5):
# the stuff you want to do goes here

HTH!

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While loop counter

2008-07-07 Thread Alan Gauld

"David" <[EMAIL PROTECTED]> wrote

Hi, I am trying to get a while loop that will execute 5 time then 
stop.


Copngratulations, you have succeeded.
Unfortunately nothing happens inside your loop. I suspect you
actually want to execute some code 5 times?


#counter = 0
#while counter < 5 :
#counter = counter + 1


Yep, this would have done it.


while True:
   mytime.tick()
   mytime.print_time()
   time.sleep(1) # Sleep for 1 second


And this loop runs forever because you never break
out of it.


counter = 0
while counter < 5 :
   counter = counter + 1


If you did get out of the infinite loop above then  this one does do 
it too.
But all it does is increment the counter. If you want code to be 
executed

it must also be inside the loop (ie inside the indented code section).

So what I think you wanted would be:

counter = 0
while counter < 5:
   mytime.tick()
   mytime.print_time()
   time.sleep(1) # Sleep for 1 second
   counter = counter + 1

But since its for a fixed number of iterations you are better
off using a for loop:

for counter in range(5)
   mytime.tick()
   mytime.print_time()
   time.sleep(1) # Sleep for 1 second

Note we don't need to increment the counter in this version.

See the loops section of my tutorial for more about for
and while loops.

HTH,

--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] python + http authentication (with cherrypy)

2008-07-07 Thread James
Hi All,

I'm writing a web application in CherryPy. What a beautiful thing it
is to write Python code and get a simple yet powerful web output. :)

The web application needs to have some decent level of security and
authentication implemented.

The big issue here is that the user password is stored in a database
and algorithmically calculated as follows:
md5( md5( $password ) + salt ) )

The salt is also stored in the database (which I have full access to).
I can easily use the md5 library to compare what a user gives me and
see if that's the correct password (based on the salt and the stored
password in the database). I'm unsure, however, how to go about
implementing security into my web application.

CherryPy obviously has a 'session' library in it. But in the periods
of time I've researched writing web applications in the past
(primarily when dealing with PHP), there was always great debate in
how to write a "good" secure web application. (i.e., it becomes tricky
when determining what precisely you should be passing around in terms
of session variables).

Thoughts? Am I going about this the wrong way? It would be much easier
to use either digest or basic http authentication mechanisms, but I
don't think that this is possible because of the fact that the
password is double-hashed in the database (or am I wrong?).

Any help appreciated. :o)

-j
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python + http authentication (with cherrypy)

2008-07-07 Thread Kent Johnson
On Mon, Jul 7, 2008 at 9:10 PM, James <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I'm writing a web application in CherryPy. What a beautiful thing it
> is to write Python code and get a simple yet powerful web output. :)
>
> The web application needs to have some decent level of security and
> authentication implemented.
>
> The big issue here is that the user password is stored in a database
> and algorithmically calculated as follows:
> md5( md5( $password ) + salt ) )

> CherryPy obviously has a 'session' library in it. But in the periods
> of time I've researched writing web applications in the past
> (primarily when dealing with PHP), there was always great debate in
> how to write a "good" secure web application. (i.e., it becomes tricky
> when determining what precisely you should be passing around in terms
> of session variables).

A typical usage is to have a session cookie that is a key into some
kind of server storage, e.g. a database table. The cookie itself
doesn't contain any information.

You might want to look at TurboGears, it uses CherryPy so it might not
be too hard  to migrate your code, and it includes an identity
subsystem that supports user-written authentication backends. See for
example
http://docs.turbogears.org/1.0/GettingStartedWithIdentity
http://docs.turbogears.org/1.0/IdentityRecipes?action=show&redirect=1.0%2FIdentityRecipies#authenticating-against-an-external-password-source

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] python + http authentication (with cherrypy)

2008-07-07 Thread Reed O'Brien

On Jul 7, 2008, at 9:10 PM, James wrote:


Hi All,

I'm writing a web application in CherryPy. What a beautiful thing it
is to write Python code and get a simple yet powerful web output. :)

The web application needs to have some decent level of security and
authentication implemented.

The big issue here is that the user password is stored in a database
and algorithmically calculated as follows:
md5( md5( $password ) + salt ) )


The salt is also stored in the database (which I have full access to).
I can easily use the md5 library to compare what a user gives me and
see if that's the correct password (based on the salt and the stored
password in the database). I'm unsure, however, how to go about
implementing security into my web application.


I had to do some stuff with salted hashed passwords a few months back  
and noted some stuff here:

http://reedobrien.blogspot.com/2008/01/seeded-salted-sha-passwords.html

md5 hash length would be 16 instead of sha's 20 IIRC... but otherwise  
I hope it helps you.





CherryPy obviously has a 'session' library in it. But in the periods
of time I've researched writing web applications in the past
(primarily when dealing with PHP), there was always great debate in
how to write a "good" secure web application. (i.e., it becomes tricky
when determining what precisely you should be passing around in terms
of session variables).

Thoughts? Am I going about this the wrong way? It would be much easier
to use either digest or basic http authentication mechanisms, but I
don't think that this is possible because of the fact that the
password is double-hashed in the database (or am I wrong?).

Any help appreciated. :o)

-j
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] While loop counter

2008-07-07 Thread David

Thank you John & Allen,

See the loops section of my tutorial for more about for
and while loops.

Yes, great tutorial, just getting it to sink in, now thats the problem :)

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] How to create array of variants?

2008-07-07 Thread Kelie
Hello group,

I'm trying to translate the following VB code into Python and not sure how to
create an array of variants. 

Thanks for your help!

VB Code:
Sub SetXdata()
Dim lineObj As AcadLine
Set lineObj = ThisDrawing.ModelSpace.Item(0)

Dim DataType(0 To 1) As Integer
Dim Data(0 To 1) As Variant

DataType(0) = 1001: Data(0) = "Test_Application"
DataType(1) = 1070: Data(1) = 600
   
lineObj.SetXdata DataType, Data
End Sub

Python code
import array
import comtypes.client

def SetXData():
activedoc =
comtypes.client.GetActiveObject("AutoCAD.Application").ActiveDocument
line = activedoc.ModelSpace.Item(0)

dataType = array.array('i', [1001, 1070])
dataValue = array.array('?', ['Test_Application', 600]) #What should I use
for the type code?

line.SetXData(dataType, dataValue)

if __name__ == "__main__":
SetXData()


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] How to create array of variants?

2008-07-07 Thread John Fouhy
On 08/07/2008, Kelie <[EMAIL PROTECTED]> wrote:
>  I'm trying to translate the following VB code into Python and not sure how to
>  create an array of variants.

I'm not sure what an array of variants in VB is -- perhaps an array
that can contain objects of any type?

>  Python code
>  import array

You may not need to use the array module -- the array module is
specifically for arrays of numerics in situations where performance
matters.  In general in Python, you get array-like behaviour using
lists.  Lists can hold objects of any type.

For example:

>>> myList = [100, 'Test application']
>>> myList[0]
100
>>> myList[1]
'Test application'

I recommend reading a python tutorial if this is new to you.

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] line class

2008-07-07 Thread Christopher Spears
For problem 13-6 out of Core Python Programming, I created a line class that 
consists of two points.  The line class has the following methods: __repr__, 
length, and slope.  Here is the code:

#!/usr/bin/python

import sys,math

class Point(object):
def __init__(self, x=0.0,y=0.0):
self.x = float(x)
self.y = float(y)

def __repr__(self):
coord = (self.x,self.y)
return coord

def __str__(self):
point_str = "(%f,%f)" % (self.x, self.y)
return point_str

class Line(object):
def __init__(self, p1, p2):
self.p1 = Point(x1,y1)
self.p2 = Point(x2,y2)

def __str__(self):
x1,y1 = self.p1.x,self.p1.y
x2,y2 = self.p2.x,self.p2.y
line = "((%f,%f),(%f,%f))" % (x1,y1,x2,y2)
return line
 
__repr__ = __str__

def length(self):
dist_x = abs(self.p2.x - self.p1.x)
dist_y = abs(self.p2.y - self.p1.y)
dist_x_squared = dist_x ** 2
dist_y_squared = dist_y ** 2
line_length = math.sqrt(dist_x_squared + dist_y_squared)
return line_length

def slope(self):
dist_y = self.p2.y - self.p1.y
dist_x = self.p2.x - self.p1.x
line_slope = dist_y/dist_x
return line_slope

if __name__ == '__main__':
print "Creating a Line"

x1 = raw_input("Enter a x1 value: ")
y1 = raw_input("Enter a y1 value: ")
p1 = Point(x1,y1)
#print p1

x2 = raw_input("Enter a x2 value: ")
y2 = raw_input("Enter a y2 value: ")
p2 = Point(x2,y2)
#print p2

line = Line(p1,p2)

print "What are the lines attributes?"
print "Select one:"
print "1) Display line"
print "2) Display line's length"
print "3) Display line's slope"
print "4) Quit program"
choice_string = raw_input("Make a choice: ")

try:
choice = int(choice_string)
except ValueError:
sys.exit("Not an integer!  Goodbye!")

if choice == 1:
print line
elif choice == 2:
line_length = line.length()
print "Length is %f " % line_length
elif choice == 3:
line_slope = line.slope()
print "Slope is %f " % line_slope
elif choice == 4:
print "Goodbye!"
else:
sys.exit("Wrong response Goodbye!")

For the most part, my script works fairly well except under the following 
circumstances:

Creating a Line
Enter a x1 value: 0
Enter a y1 value: 0
Enter a x2 value: 0
Enter a y2 value: 1
What are the lines attributes?
Select one:
1) Display line
2) Display line's length
3) Display line's slope
4) Quit program
Make a choice: 3
Traceback (most recent call last):
  File "line.py", line 79, in ?
line_slope = line.slope()
  File "line.py", line 42, in slope
line_slope = dist_y/dist_x
ZeroDivisionError: float division

Basically, if the two the x values are the same, I will get a 
ZeroDivisionError.  A line in this case would simply point straight up.  What 
would slope be in this case?  I will admit that this is probably a math problem 
not a programming one, but I decided to run it by you anyway.

Thanks.


  
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Unzipping a list

2008-07-07 Thread Faheem
hey all,
 How can i pass the elements of a list in the follwoing manner?
  
 L =['ask'.'tell','repeat','sell']
 
 To illustrate my question:
 how can i pass the above list as follows
 
"/some/program/run -o ask tell repeat sell"

thanks in advance
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] line class

2008-07-07 Thread John Fouhy
On 08/07/2008, Christopher Spears <[EMAIL PROTECTED]> wrote:
>  Basically, if the two the x values are the same, I will get a 
> ZeroDivisionError.  A line in this
> case would simply point straight up.  What would slope be in this case?  I 
> will admit that
> this is probably a math problem not a programming one, but I decided to run 
> it by you
> anyway.

The slope in this case is undefined.  Throwing an exception seems to
be a pretty reasonable way of dealing with this case, to be honest.
(although if you're keen, you could define your own
"UndefinedSlopeError" or "VerticalLineError" exception and raise that
instead of the ZeroDivisionError)

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor