From Matthias.Sommer at wincor-nixdorf.com Tue Apr 1 10:53:52 2008
From: Matthias.Sommer at wincor-nixdorf.com (Sommer, Matthias)
Date: Tue, 1 Apr 2008 10:53:52 +0200
Subject: [Tutor] simple,
probably stupid question: single key in console / idle
Message-ID: <8D64EA9FED068444B02447C8EFE810D80BC4D8@DEEXVS03.wincor-nixdorf.com>
Hello,
I'm just starting programming in Python. ATM I do write some smaller practices. In them I want to read single keys, if pressed. If none pressed I do not want to wait.
In the library reference I found "kbhit()" and "getch()" from msvcrt. I import msvcrt (running on Windows) but I cant get it to run. Is ther somewhere a sample I could peek on?
And is there somthing not windows specific?
My trial code is:
import msvcrt
def kb():
while( 1 ):
if msvcrt.kbhit():
print "key seen"
help = msvcrt.getch()
#if( help < 255 ):
print help, ord( help )
if( ord( help ) == 27 ):
print "cancel"
break
It appears to never see a key.
Mit freundlichen Gr??en
Matthias Sommer
Entwicklung - Firmware/Elektronik
______________________________________________
Wincor Nixdorf Technology GmbH
Am Vogelherd 67
D - 98693 Ilmenau, Germany
Tel.: +49 (0) 36 77 862-194
Fax: +49 (0) 36 77 862-199
E-Mail: matthias.sommer at wincor-nixdorf.com
www.wincor-nixdorf.com
--
Wincor Nixdorf Technology GmbH
Sitz der Gesellschaft: Paderborn
Registergericht Paderborn HRB 3523
Gesch?ftsf?hrer: Eckard Heidloff, J?rgen Wilde, Wolfgang Keller
Steuernummer: 339/5884/0020 - Ust-ID Nr.: DE243233085
Diese E-Mail enth?lt vertrauliche Informationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrt?mlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet.
This e-mail may contain confidential information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/5313e5cd/attachment.htm
From onyxtic at gmail.com Tue Apr 1 14:42:43 2008
From: onyxtic at gmail.com (Evans Anyokwu)
Date: Tue, 1 Apr 2008 13:42:43 +0100
Subject: [Tutor] Testing 321
Message-ID:
Please ignore, switching email address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/283d2096/attachment.htm
From alan.gauld at btinternet.com Tue Apr 1 14:43:59 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 1 Apr 2008 13:43:59 +0100
Subject: [Tutor] simple,
probably stupid question: single key in console / idle
References: <8D64EA9FED068444B02447C8EFE810D80BC4D8@DEEXVS03.wincor-nixdorf.com>
Message-ID:
"Sommer, Matthias" wrote
> In the library reference I found "kbhit()" and "getch()" from
> msvcrt.
> I import msvcrt (running on Windows) but I cant get it to run.
> Is ther somewhere a sample I could peek on?
You can look at the event handling topic in my tutor.
It goves an example of reading keys with getch()
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From mlangford.cs03 at gtalumni.org Tue Apr 1 19:30:46 2008
From: mlangford.cs03 at gtalumni.org (Michael Langford)
Date: Tue, 1 Apr 2008 13:30:46 -0400
Subject: [Tutor] Interactive plots...
In-Reply-To:
References:
Message-ID: <82b4f5810804011030t4a7ec76dtef847f6018299f81@mail.gmail.com>
If you're just talking about something like this (ascii art) drawing:
--------------------------------------------------------------------------------------------
1:* * * * * * * * * *
0: * * * * * * * * * * * * * * * * * * *
---------------------------------------------------------------------------------------------
Then I think you have a relatively simple alternative for a UI:
Create a scrollable UI in the toolkit of your choice. It scrolls left to
right. Make a series of radiobutton selections with all of the UI components
matching the background color. That way you only get the actual clickable
dots. Then your users can click on the dot to move it to the opposite
position (by overriding the on-click handler).
A rough tkinter solution without scrolling, the selection buttons removed,
or the switching logic follows this reply. You can make the following nicer
by rewriting the click command, and you can probably find a way to make
tkinter hide the empty circles or use a different toolkit to implement the
same idea. You should be able to put an X axis in to show time or whatever
dimension your data is over.
--Michael
from Tkinter import *
def createDataPoint(master,var):
rb1
=Radiobutton(master,borderwidth=0,foreground='red',background='white',variable=var,value=1)
rb1.grid()
rb2=Radiobutton(master,borderwidth=0,foreground='red',background='white',variable=var,value=0)
rb2.grid()
class Application(Frame):
def __init__(self, master=None,data=[1]):
Frame.__init__(self, master)
self.grid()
self.data = data
self.createWidgets()
def show(self):
l = []
for each in self.ivlist:
l.append(each.get())
print(l)
def createWidgets(self):
self.showButton = Button ( self, text="Show",
command=self.show )
self.showButton.grid(row=0)
self.ivlist = []
for i in range(len(self.data)):
iv = IntVar(value=self.data[i])
self.ivlist.append(iv)
f = Frame(self)
f.grid(column=i+1,row=1)
createDataPoint(f,iv)
if "__main__"==__name__:
data = [1,0,1,0,1,1,1,1,0,1]
app = Application(data=data)
app.master.title("Flippin DOTS")
app.mainloop()
On Thu, Mar 27, 2008 at 6:54 PM, David Perlman wrote:
> I am thinking about writing a program which will involve, among other
> things, displaying a plot of a series of numbers. The idea is that
> you could click on the points and move them to change the numbers.
> Reverse-plotting, I suppose. It need not be complex; the numbers
> will all be zero or one, and it's only necessary to flip the bits, so
> click-and-drag is seriously overkill. Really it would be better to
> just double-click on a point to switch it from one value to the other.
>
> Can anyone point me in the right direction? I have written some
> programs in python before, including TKinter, but this new project is
> beyond the point that I know where to even start looking. :)
>
> In case you care, the application is in functional brain imaging; the
> brain scans generate a certain number of time points (say 500) and
> then the motion of the subject is also calculated. Standard practice
> is to generate a "censor" file composed of zeros and ones, where zero
> indicates that that time point had excessive motion and must be
> disregarded. I want to display a graph of the motion over time, and
> allow quick and easy interactive editing of the censor time series in
> visual parallel to the motion graph. This would save a lot of time;
> at present everyone does this in Excel, which being a horrible
> Windows program can't be integrated into the predominantly UNIX-based
> processing pipeline. And in any case, it requires manually typing
> all the zeros, looking back and forth between the graph of motion and
> the list of numbers.
>
> I have already written a program to algorithmically generate the
> censor time series from the motion data, but it is absolutely
> essential to be able to manually double-check and if necessary make
> minor edits. I'd like to be able to keep that functionality in
> Python rather than sending everyone back to Excel... if possible!
>
> Thanks very much for any help.
>
> --
> -dave----------------------------------------------------------------
> "Pseudo-colored pictures of a person's brain lighting up are
> undoubtedly more persuasive than a pattern of squiggles produced by a
> polygraph. That could be a big problem if the goal is to get to the
> truth." -Dr. Steven Hyman, Harvard
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/3890a831/attachment.htm
From mlangford.cs03 at gtalumni.org Tue Apr 1 19:51:18 2008
From: mlangford.cs03 at gtalumni.org (Michael Langford)
Date: Tue, 1 Apr 2008 13:51:18 -0400
Subject: [Tutor] Problem with logic while extracting data from binary
file
In-Reply-To:
References:
<47E9900C.6080200@alum.rpi.edu>
<47EA9D7D.7070008@alum.rpi.edu>
<47EC22F4.8030105@alum.rpi.edu>
<47EC4E09.5030407@alum.rpi.edu>
Message-ID: <82b4f5810804011051i2c3b3091wd1412929b306c18@mail.gmail.com>
I tried to extract methods, and invert your logic of your if/else statements
as to put shorter code blocks higher, and tried to roll many of your if
statements into the checks of the while loops. This is algorithm I ended up
with. Is this what you were trying to do? The last while loop is pointless,
as you unconditionally return from it.
--Michael
def basicFields(data,start):
group_num = data[start:start+2]
element_num = data[start+2:start+4]
vl_field = data[start+4:start+8]
length = struct.unpack('hh', vl_field)[0]
value = data[start+8:(start+8+length)]
start = start+8+length
element = group_num+element_num
return (group_num,element_num,vl_field,length,value,start,element)
def parseSequence(data, start):
group_num,element_num,vl_field,length,value,pos,element =
basicFields(data,start)
MY_SEQ = '\xfe\xff\x00\xe0'
while start < 536: #length: # 536
group_num,element_num,vl_field,length,value,start,element =
basicFields(data,start)
if element != MY_SEQ:
return element, start, value
else:
data = value
while start < 112: #length: # 112, 112, 116, 116
group_num,element_num,vl_field,length,value,start,element =
basicFields(data,start)
return element, start, value
On Fri, Mar 28, 2008 at 4:24 PM, Bryan Fodness
wrote:
>
> Thanks again,
>
> Still lost, even with watching the variables. I see that it kicks out of
> the loop, but don't understand what I have done to cause this. I'm sorry
> for repeated emails, but I have spent multiple days on this. I have added
> another while loop that I think should work, but I can't seem to keep it in
> the while loop. I feel like I am getting close.
>
> It seems like it gets everything at the first level , but not the way I
> expected. It seems to get the first value inside the first while loop, and
> then goes outside the loop to get the next three. I would have expected it
> to return the values as it goes through the first while loop (since they are
> at the same level), then when it sees the nested identifier, go into the
> second while loop and return values.
>
> Any insight would be wonderful.
>
> def parseSequence(data, start):
> group_num = data[start:start+2]
> element_num = data[start+2:start+4]
> vl_field = data[start+4:start+8]
> length = struct.unpack('hh', vl_field)[0]
> value = data[start+8:(start+8+length)]
> pos = start+8+length
> element = (group_num+element_num)
> if element == '\xfe\xff\x00\xe0':
> data = value
> while start < 536: #length: # 536
> group_num = data[start:start+2]
> element_num = data[start+2:start+4]
> vl_field = data[start+4:start+8]
> length = struct.unpack('hh', vl_field)[0]
> value = data[start+8:(start+8+length)]
> start = start+8+length
> element = (group_num+element_num)
> if element == '\xfe\xff\x00\xe0':
> data = value
> while start < 112: #length: # 112, 112, 116, 116
> group_num = data[start:start+2]
> element_num = data[start+2:start+4]
> vl_field = data[start+4:start+8]
> length = struct.unpack('hh', vl_field)[0]
> value = data[start+8:(start+8+length)]
> start = start+8+length
> element = (group_num+element_num)
> return element, start, value
> else:
> return element, start, value
> else:
> return element, pos, value
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/30f48b01/attachment-0001.htm
From pylinuxian at gmail.com Tue Apr 1 23:07:04 2008
From: pylinuxian at gmail.com (linuxian iandsd)
Date: Tue, 1 Apr 2008 21:07:04 +0000
Subject: [Tutor] parse emails as they come in
In-Reply-To: <200803312109.49656.cfuller084@thinkingplanet.net>
References:
<200803280808.20625.cfuller084@thinkingplanet.net>
<200803312109.49656.cfuller084@thinkingplanet.net>
Message-ID:
well, my script is so simple ! nothing complicated
#!/usr/bin/python
#
import re, sys
a=open('/home/john/data/file_input.tmp', 'r')
b=open('/home/john/data/file_output', 'w')
aa=a.readlines()
n=0
for L in aa:
# I split every line because i only need what's after the ":"
# the email comes in the form "field : value" in 17 lines
La=L.split(':')
n=n+1
# 18 is the last line & it is an empty line that comes with every email
# so i quit there.
if n==18:
sys.exit()
# second line is a time value like this one "18:20:45"
# i don't need the ":" but i need the numbers
elif n==2:
# as usual i remove the \n & put a ; in its place and that happens
# at the third element
La3=re.sub('\n',';',La[3])
# i gather the time value also there is no need for : in between
La123=La[1]+La[2]+La3
b.write(La123)
# any other line is treated equaly like this
# i only replace \n by ;
else:
La1=re.sub('\n',';',La[1])
b.write(La1)
# a little secret : this little script helps me load data from mail to a
mysql database by converting it into ; separated values :)
On Tue, Apr 1, 2008 at 2:09 AM, Chris Fuller
wrote:
> Every five lines of the raw email, the headers, or the body?
>
> A text file is just data. You can navigate however you like, but you need
> to
> choose a model, to give it some structure for you to work with,
> Navigating
> around at the byte level is probably going to be tedious, error prone, and
> not very useful anyway. Choosing five lines at a time is probably not
> going
> to be much better. There's no particular reason it can't be ten lines, or
> two, unless you pick a model that
>
> Maybe we could help more if you showed us what this "original script" is.
> We
> can help you pick a better model if the one implicit in your script isn't
> working for you.
>
> Also, you should probably reply to the mailing list.
> I'll be more careful about the reply-to field from now on.
>
> Cheers
>
>
> On Monday 31 March 2008 14:43, you wrote:
> > the mail module seems interesting. but what I was thinking of some way
> > that would work on only five lines then moves to the next five lines &
> so
> > on ... is that possible ? is there a way of navigating a text file ?
> > process the line that we want, maybe delete it or maybe add text to it
> &
> > then save & close the file ?
> >
> >
> > On Fri, Mar 28, 2008 at 1:08 PM, Chris Fuller
> >
> >
> > wrote:
> > > The email and mailbox modules might help you out. Multiple email
> > > messages will probably parse as an mbox format mailbox.
> > >
> > > http://docs.python.org/lib/module-email.html
> > > http://docs.python.org/lib/module-mailbox.html
> > >
> > > Cheers
> > >
> > > On Friday 28 March 2008 03:14, linuxian iandsd wrote:
> > > > good morning everybody !
> > > >
> > > > I have scripted a small program to parse a 5 lines email message as
> it
> > > > comes in to my inbox (this is handled by procmail & here is a
> wonderful
> > > > intro to it :
> http://linuxfocus.org/English/November1997/article8.html)
> > > >
> > > > so every email is being parsed & information is extracted from it.
> > > >
> > > > but sometimes two or more emails come in at once so the input file
> that
> > >
> > > my
> > >
> > > > python script has to parse is more than five lines !! my question is
> > > > how
> > >
> > > do
> > >
> > > > i effeciently manage this from within my original script.
> > > >
> > > > thanks
> > >
> > > _______________________________________________
> > > Tutor maillist - Tutor at python.org
> > > http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/86fd7afa/attachment.htm
From alan.gauld at btinternet.com Tue Apr 1 22:29:10 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Tue, 1 Apr 2008 21:29:10 +0100
Subject: [Tutor] simple,
probably stupid question: single key in console / idle
References: <8D64EA9FED068444B02447C8EFE810D80BC4D8@DEEXVS03.wincor-nixdorf.com>
Message-ID:
"Alan Gauld" wrote
>> I import msvcrt (running on Windows) but I cant get it to run.
>> Is ther somewhere a sample I could peek on?
>
I just noticed the bit about IDLE in the subject.
msvcrt only works in a DOS console it won't work in
IDLE because IDLE is detecting the keyboard events
as GUI events within Tkinter. You will need to run
your code in a command console not IDLE.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From steve at alchemy.com Tue Apr 1 23:17:30 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Tue, 1 Apr 2008 14:17:30 -0700
Subject: [Tutor] parse emails as they come in
In-Reply-To:
References:
<200803280808.20625.cfuller084@thinkingplanet.net>
<200803312109.49656.cfuller084@thinkingplanet.net>
Message-ID: <20080401211730.GA75799@dragon.alchemy.com>
On Tue, Apr 01, 2008 at 09:07:04PM +0000, linuxian iandsd wrote:
> a=open('/home/john/data/file_input.tmp', 'r')
> b=open('/home/john/data/file_output', 'w')
This is collecting mail as it comes in? If you have a mail
rule in place to dump mail into this file_input.tmp file,
you could run into trouble if multiple messages arrive close
enough together that you get a race condition.
I'd suggest just using something like procmail to invoke
your Python script directly on the incoming message, so
you don't have to dump it to a temporary input file.
You'll be guaranteed to see one and only one mail per
invocation of your script (although it may invoke
several copies of your script at the same time, so plan
for that, e.g., don't write to the same output filename
every time--or don't write to a file at all, just have
your script put the data into MySQL or whatever directly).
> aa=a.readlines()
> n=0
> for L in aa:
Generally speaking, it's better to let Python iterate
through the lines of a file. The above code sucks in
the entire (possibly huge) file into memory and then
iterates over that list. Better:
for L in a:
or better yet:
for lines in input_file:
> # a little secret : this little script helps me load data from mail to a
> mysql database by converting it into ; separated values :)
I'd look at just gathering the raw data into Python variables and then
connecting to MySQL directly and executing a SQL statement to import the
data straight in. You'll avoid a host of problems with properly quoting
data (what if a ';' is in one of the data fields?), as well as making it
unnecessary to carry out another post-processing step of gathering this
script's output and stuffing it into MySQL.
--
Steve Willoughby | Using billion-dollar satellites
steve at alchemy.com | to hunt for Tupperware.
From wescpy at gmail.com Tue Apr 1 23:46:26 2008
From: wescpy at gmail.com (wesley chun)
Date: Tue, 1 Apr 2008 14:46:26 -0700
Subject: [Tutor] [ANN] May 2008 Python course
In-Reply-To: <78b3a9580804011444v388d5690m4d9a3931da4523a2@mail.gmail.com>
References: <78b3a9580804011444v388d5690m4d9a3931da4523a2@mail.gmail.com>
Message-ID: <78b3a9580804011446r3c03d07bl94e001fd492c8bf7@mail.gmail.com>
* apologies if you receive cross-posted duplicates *
FINAL REMINDER
Need to get up-to-speed with Python as quickly as possible? Come join
me, Wesley Chun, author of Prentice-Hall's well-received "Core Python
Programming," for another comprehensive intro course next month in
beautiful Northern California! I look forward to meeting you! If you
miss this one, our next courses will likely be in Oct or Nov 2008.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(COMPREHENSIVE) INTRODUCTION TO PYTHON: Mon-Wed, 2008 May 5-7
Although this course may appear to those new to Python, it is also
perfect those who have tinkered with it and want to "fill in the gaps"
and/or want to get more in-depth formal training. It combines the
best of both an introduction to the language as well as a "Python
Internals" training course.
We will immerse you in the world of Python in only a few days. We
will show you more than just its syntax (which you don't really need a
book to learn, right?). Knowing more about how Python works under the
covers, including the relationship between data objects and memory
management, will make you a much more
effective Python programmer coming out of the gate. 3 hands-on labs
each day will help hammer the concepts home.
Come find out why Google, Yahoo!, Disney, ILM/LucasFilm, VMware, OLPC,
NASA, Ubuntu, YouTube, and Red Hat all use Python. Users supporting or
jumping to Plone, Zope, TurboGears, Django, Pylons, Jython,
IronPython, and Mailman will also benefit!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
WHERE: near the San Francisco Airport (SFO/San Bruno), CA, USA
WEB: http://cyberwebconsulting.com (click "Python Training")
LOCALS: easy freeway (101/280/380) with lots of parking plus public
transit (BART and CalTrain) access via the San Bruno stations, easily
accessible from all parts of the Bay Area
VISITORS: free shuttle to/from the airport, free high-speed internet,
free breakfast and regular evening receptions; fully-equipped suites
See website for costs, venue info, and registration. Discounts are
available for multiple registrations as well as for teachers/students.
Hope to see you there!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Core Python Programming", Prentice Hall, (c)2007,2001
http://corepython.com
wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
From wtfwhoami at gmail.com Wed Apr 2 01:29:21 2008
From: wtfwhoami at gmail.com (Guess?!?)
Date: Tue, 1 Apr 2008 16:29:21 -0700
Subject: [Tutor] Sync between Powerpoint slides and Video
Message-ID: <8c64f3990804011629k776fbbf7wf5e85f345a992187@mail.gmail.com>
Hello All,
I recently came across couple of websites (www.parleys.com and
www.zentation.com) and loved the sync technology between ppt and streaming
video. This makes website experience look fast and impressive. I was just
curious to know the how is it all done. What technology/software is being
used to sync powerpoint presentations with video?
If anyone has delved into implementing this in Python or Zope/Plone
frameworks or any other technology ...Please share the knowledge ....
Any insight will be appreciated ...
Thanks,
G Arora.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/b9e21f8a/attachment.htm
From hunter92383 at gmail.com Wed Apr 2 02:14:37 2008
From: hunter92383 at gmail.com (elis aeris)
Date: Tue, 1 Apr 2008 17:14:37 -0700
Subject: [Tutor] how do I use windows.h with python?
Message-ID: <674d5ce60804011714t29990dc9paad843e66aabccf2@mail.gmail.com>
this is a sample code that use window.h function i THINK.
where can I read up on windll ?
class RECT(Structure):
_fields_ = [
('left', c_ulong),
('top', c_ulong),
('right', c_ulong),
('bottom', c_ulong)
]
# time.sleep(2)
GetForegroundWindow = windll.user32.GetForegroundWindow
GetWindowRect = windll.user32.GetWindowRect
# Grab the foreground window's screen rectangle.
rect = RECT()
foreground_window = GetForegroundWindow()
GetWindowRect(foreground_window, byref(rect))
image = ImageGrab.grab((rect.left, rect.top, rect.right, rect.bottom))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/05e68048/attachment.htm
From alan.gauld at btinternet.com Wed Apr 2 02:45:36 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 2 Apr 2008 01:45:36 +0100
Subject: [Tutor] how do I use windows.h with python?
References: <674d5ce60804011714t29990dc9paad843e66aabccf2@mail.gmail.com>
Message-ID:
"elis aeris" wrote
> this is a sample code that use window.h function i THINK.
>
> where can I read up on windll ?
The Windows API is documented on the MSDN website.
Alternatively find a copy of the Win32API help file, it is usually
distributed with development tools like Visual studio, Delphi, etc
Try Googling win32.hlp for links to older copies.
Also Wikipedia has a good overview with more links.
Finally the Pythonwin help file has a lot of the same info
but is ISTR more targetted at the MFC classes than the
raw Win32 API.
If you do intend to use Win32 from Python then Google
for ctypes tutorials/examples too. But whatever you want
to do there will almost always be easier ways to do it
without going near Win32! But if you really want to make
life hard for yourself the links above should help get you
started.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From hunter92383 at gmail.com Wed Apr 2 02:50:03 2008
From: hunter92383 at gmail.com (elis aeris)
Date: Tue, 1 Apr 2008 17:50:03 -0700
Subject: [Tutor] how do I use windows.h with python?
In-Reply-To:
References: <674d5ce60804011714t29990dc9paad843e66aabccf2@mail.gmail.com>
Message-ID: <674d5ce60804011750w630a47a1r2e041bb220663865@mail.gmail.com>
I know how to check msdn site, but I don't understand how things are
organized under windll
where do they have this ?
On Tue, Apr 1, 2008 at 5:45 PM, Alan Gauld
wrote:
>
> "elis aeris" wrote
>
> > this is a sample code that use window.h function i THINK.
> >
> > where can I read up on windll ?
>
> The Windows API is documented on the MSDN website.
> Alternatively find a copy of the Win32API help file, it is usually
> distributed with development tools like Visual studio, Delphi, etc
>
> Try Googling win32.hlp for links to older copies.
>
> Also Wikipedia has a good overview with more links.
>
> Finally the Pythonwin help file has a lot of the same info
> but is ISTR more targetted at the MFC classes than the
> raw Win32 API.
>
> If you do intend to use Win32 from Python then Google
> for ctypes tutorials/examples too. But whatever you want
> to do there will almost always be easier ways to do it
> without going near Win32! But if you really want to make
> life hard for yourself the links above should help get you
> started.
>
>
> HTH,
>
> --
> Alan Gauld
> Author of the Learn to Program web site
> http://www.freenetpages.co.uk/hp/alan.gauld
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080401/cf545711/attachment.htm
From pylinuxian at gmail.com Wed Apr 2 08:52:48 2008
From: pylinuxian at gmail.com (linuxian iandsd)
Date: Wed, 2 Apr 2008 06:52:48 +0000
Subject: [Tutor] parse emails as they come in
In-Reply-To: <20080401211730.GA75799@dragon.alchemy.com>
References:
<200803280808.20625.cfuller084@thinkingplanet.net>
<200803312109.49656.cfuller084@thinkingplanet.net>
<20080401211730.GA75799@dragon.alchemy.com>
Message-ID:
ok - as i mentioned in my first email i use procmail to put THE BODY of all
incoming mail into a file (that is one per incoming email as i use the
variable $date-$time in the name).
now this file can contain only one email but it can also contain 2 or more
(this happens if for example there is a dns problem in the internet, so mail
can't make it, but once internet recovers from the dns problem mail rushes
in & we may have multiple messages per file. this is also true is i do this
cmd :
for i in 1 2 3 4 5 6 ; do echo $i | mail -s 'test mail' john ; done
well, this file is processed by my script to extract data.
the problem is : i can parse 18 lines (that is one email per file) fine, but
i need suggestions in parsing it when it contains two emails (that is 18
lines + 18 lines ....)
i hope i have explained my problem well this time.
i will make the optimizations you told me (directly inserting data into
mysql & the lines loop as well)
thanks a lot.
On Tue, Apr 1, 2008 at 9:17 PM, Steve Willoughby wrote:
> On Tue, Apr 01, 2008 at 09:07:04PM +0000, linuxian iandsd wrote:
> > a=open('/home/john/data/file_input.tmp', 'r')
> > b=open('/home/john/data/file_output', 'w')
>
> This is collecting mail as it comes in? If you have a mail
> rule in place to dump mail into this file_input.tmp file,
> you could run into trouble if multiple messages arrive close
> enough together that you get a race condition.
>
> I'd suggest just using something like procmail to invoke
> your Python script directly on the incoming message, so
> you don't have to dump it to a temporary input file.
> You'll be guaranteed to see one and only one mail per
> invocation of your script (although it may invoke
> several copies of your script at the same time, so plan
> for that, e.g., don't write to the same output filename
> every time--or don't write to a file at all, just have
> your script put the data into MySQL or whatever directly).
>
> > aa=a.readlines()
> > n=0
> > for L in aa:
>
> Generally speaking, it's better to let Python iterate
> through the lines of a file. The above code sucks in
> the entire (possibly huge) file into memory and then
> iterates over that list. Better:
>
> for L in a:
>
> or better yet:
>
> for lines in input_file:
>
> > # a little secret : this little script helps me load data from mail to a
> > mysql database by converting it into ; separated values :)
>
> I'd look at just gathering the raw data into Python variables and then
> connecting to MySQL directly and executing a SQL statement to import the
> data straight in. You'll avoid a host of problems with properly quoting
> data (what if a ';' is in one of the data fields?), as well as making it
> unnecessary to carry out another post-processing step of gathering this
> script's output and stuffing it into MySQL.
>
> --
> Steve Willoughby | Using billion-dollar satellites
> steve at alchemy.com | to hunt for Tupperware.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/f7cdf61e/attachment.htm
From steve at alchemy.com Wed Apr 2 09:18:00 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Wed, 02 Apr 2008 00:18:00 -0700
Subject: [Tutor] parse emails as they come in
In-Reply-To:
References: <200803280808.20625.cfuller084@thinkingplanet.net> <200803312109.49656.cfuller084@thinkingplanet.net> <20080401211730.GA75799@dragon.alchemy.com>
Message-ID: <47F33328.9050609@alchemy.com>
linuxian iandsd wrote:
> ok - as i mentioned in my first email i use procmail to put THE BODY of all
> incoming mail into a file (that is one per incoming email as i use the
> variable $date-$time in the name).
>
> now this file can contain only one email but it can also contain 2 or more
> (this happens if for example there is a dns problem in the internet, so mail
> can't make it, but once internet recovers from the dns problem mail rushes
> in & we may have multiple messages per file. this is also true is i do this
Using $date-$time is insufficient since I'll wager a dozen doughnuts
that the resolution of $time isn't small enough compared to the speed
messages can arrive.
But as I tried to explain in my previous mail, this is a problem you
don't have to solve. By choosing to use procmail to dump a file with
a non-unique name, you create a race condition you then have to deal
with in your code.
If, on the other hand, you use procmail to _filter_ the message
through your script, this cannot possibly happen. You'll get an
invocation of your script per message every time. If you have
your script directly dump the data into MySQL you never need to
write any disk files at all.
From alan.gauld at btinternet.com Wed Apr 2 09:42:26 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 2 Apr 2008 08:42:26 +0100
Subject: [Tutor] how do I use windows.h with python?
References: <674d5ce60804011714t29990dc9paad843e66aabccf2@mail.gmail.com>
<674d5ce60804011750w630a47a1r2e041bb220663865@mail.gmail.com>
Message-ID:
"elis aeris" wrote
>I know how to check msdn site, but I don't understand how things are
> organized under windll
>
> where do they have this ?
>
>>
>> Also Wikipedia has a good overview with more links.
>>
>> Finally the Pythonwin help file has a lot of the same info
>> but is ISTR more targetted at the MFC classes than the
>> raw Win32 API.
>>
Alan G
From steve at alchemy.com Wed Apr 2 11:50:18 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Wed, 02 Apr 2008 02:50:18 -0700
Subject: [Tutor] parse emails as they come in
In-Reply-To:
References:
<200803280808.20625.cfuller084@thinkingplanet.net>
<200803312109.49656.cfuller084@thinkingplanet.net>
<20080401211730.GA75799@dragon.alchemy.com>
<47F33328.9050609@alchemy.com>
Message-ID: <47F356DA.4070303@alchemy.com>
linuxian iandsd wrote:
> well, i don't know how to pipe the file to my script !!
It's how procmail works. Presuming you looked up how to write
a procmail rule to save the body of your mail into a file, you
should also see right next to it the instructions for piping
the message to a program. (It also can be found by a quick
Google search, for future reference if you want a quick answer.)
You just put a "|" symbol in front of the script name.
To save the message to a file, you'd say something like
:0:
*Subject:.*pattern to look for
/home/me/temp_input_file$date$time
To pipe it to your script, you'd say something like
:0
*Subject:.*pattern to look for
|/home/me/scriptname
For more information see procmailrc(5) and procmailex(5).
Your Python script will see the message input on stdin.
>
> On Wed, Apr 2, 2008 at 7:18 AM, Steve Willoughby wrote:
>
>> linuxian iandsd wrote:
>>> ok - as i mentioned in my first email i use procmail to put THE BODY of
>> all
>>> incoming mail into a file (that is one per incoming email as i use the
>>> variable $date-$time in the name).
>>>
>>> now this file can contain only one email but it can also contain 2 or
>> more
>>> (this happens if for example there is a dns problem in the internet, so
>> mail
>>> can't make it, but once internet recovers from the dns problem mail
>> rushes
>>> in & we may have multiple messages per file. this is also true is i do
>> this
>>
>> Using $date-$time is insufficient since I'll wager a dozen doughnuts
>> that the resolution of $time isn't small enough compared to the speed
>> messages can arrive.
>>
>> But as I tried to explain in my previous mail, this is a problem you
>> don't have to solve. By choosing to use procmail to dump a file with
>> a non-unique name, you create a race condition you then have to deal
>> with in your code.
>>
>> If, on the other hand, you use procmail to _filter_ the message
>> through your script, this cannot possibly happen. You'll get an
>> invocation of your script per message every time. If you have
>> your script directly dump the data into MySQL you never need to
>> write any disk files at all.
>>
>>
>
From pylinuxian at gmail.com Wed Apr 2 12:20:41 2008
From: pylinuxian at gmail.com (linuxian iandsd)
Date: Wed, 2 Apr 2008 10:20:41 +0000
Subject: [Tutor] parse emails as they come in
In-Reply-To: <47F356DA.4070303@alchemy.com>
References:
<200803280808.20625.cfuller084@thinkingplanet.net>
<200803312109.49656.cfuller084@thinkingplanet.net>
<20080401211730.GA75799@dragon.alchemy.com>
<47F33328.9050609@alchemy.com>
<47F356DA.4070303@alchemy.com>
Message-ID:
well, here is a piece of final script :
#!/usr/bin/python
#
import sys
b=[]
while 1:
data = sys.stdin.readline()
if data != '\n':
b.append(data)
else:
break
for i in (0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16):
b[i]=b[i].split(':')[1].strip()
#print b[i]
b[1]=b[1].split(':')
b[1]=b[1][1]+b[1][2]+b[1][3].strip()
#print b[1][1]+b[1][2]+b[1][3].strip()
bb=",".join(b)
print bb
mysqlcmd='insert into webdata field1, field2, field3, field4, field5,
field6, field7 ..... field17 values (%s)' % bb
print mysqlcmd
END OF SCRIPT
the parsed file looks like this :
field1: xxxxx
field2: xxxxx
....
field17: xxxxx
empty line here for end of message
On Wed, Apr 2, 2008 at 9:50 AM, Steve Willoughby wrote:
> linuxian iandsd wrote:
>
> > well, i don't know how to pipe the file to my script !!
> >
>
> It's how procmail works. Presuming you looked up how to write
> a procmail rule to save the body of your mail into a file, you
> should also see right next to it the instructions for piping
> the message to a program. (It also can be found by a quick
> Google search, for future reference if you want a quick answer.)
>
> You just put a "|" symbol in front of the script name.
>
> To save the message to a file, you'd say something like
>
> :0:
> *Subject:.*pattern to look for
> /home/me/temp_input_file$date$time
>
> To pipe it to your script, you'd say something like
>
> :0
> *Subject:.*pattern to look for
> |/home/me/scriptname
>
> For more information see procmailrc(5) and procmailex(5).
>
> Your Python script will see the message input on stdin.
>
>
>
> > On Wed, Apr 2, 2008 at 7:18 AM, Steve Willoughby
> > wrote:
> >
> > linuxian iandsd wrote:
> > >
> > > > ok - as i mentioned in my first email i use procmail to put THE BODY
> > > > of
> > > >
> > > all
> > >
> > > > incoming mail into a file (that is one per incoming email as i use
> > > > the
> > > > variable $date-$time in the name).
> > > >
> > > > now this file can contain only one email but it can also contain 2
> > > > or
> > > >
> > > more
> > >
> > > > (this happens if for example there is a dns problem in the internet,
> > > > so
> > > >
> > > mail
> > >
> > > > can't make it, but once internet recovers from the dns problem mail
> > > >
> > > rushes
> > >
> > > > in & we may have multiple messages per file. this is also true is i
> > > > do
> > > >
> > > this
> > >
> > > Using $date-$time is insufficient since I'll wager a dozen doughnuts
> > > that the resolution of $time isn't small enough compared to the speed
> > > messages can arrive.
> > >
> > > But as I tried to explain in my previous mail, this is a problem you
> > > don't have to solve. By choosing to use procmail to dump a file with
> > > a non-unique name, you create a race condition you then have to deal
> > > with in your code.
> > >
> > > If, on the other hand, you use procmail to _filter_ the message
> > > through your script, this cannot possibly happen. You'll get an
> > > invocation of your script per message every time. If you have
> > > your script directly dump the data into MySQL you never need to
> > > write any disk files at all.
> > >
> > >
> > >
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/54405d8e/attachment.htm
From hihiren1 at gmail.com Wed Apr 2 13:21:25 2008
From: hihiren1 at gmail.com (hiren kumar)
Date: Wed, 2 Apr 2008 16:51:25 +0530
Subject: [Tutor] Question about Python ORM
Message-ID:
Hi,
I am very much new to Python and it's available framework.
When I search the over net about Python ORM, I found there are so many ORMs
available and I was confused between them? I don't understand where to go?
:(
Can you please tell me something about Python ORM?
Regards,
Kumar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/65d2f879/attachment.htm
From andreas at kostyrka.org Wed Apr 2 13:25:05 2008
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Wed, 02 Apr 2008 13:25:05 +0200
Subject: [Tutor] Question about Python ORM
In-Reply-To:
References:
Message-ID: <1207135505.8299.91.camel@localhost>
There are many as you said yourself. Recommendation: sqlalchemy.org
Andreas
Am Mittwoch, den 02.04.2008, 16:51 +0530 schrieb hiren kumar:
> Hi,
>
> I am very much new to Python and it's available framework.
>
> When I search the over net about Python ORM, I found there are so many
> ORMs available and I was confused between them? I don't understand
> where to go? :(
>
> Can you please tell me something about Python ORM?
>
> Regards,
> Kumar
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080402/3d195431/attachment.pgp
From wwerner at swbell.net Wed Apr 2 14:07:53 2008
From: wwerner at swbell.net (WW)
Date: Wed, 2 Apr 2008 07:07:53 -0500
Subject: [Tutor] asyncore/asynchat
Message-ID: <333efb450804020507h33afd581va6a4820b5ba711e6@mail.gmail.com>
Hi, I'm new to the list, and fairly new-ish to python. I'd rate my
programming experience as beginning-intermediate, and I've had some
experience with c++ and VBS, and I'm currently a freshman CS major.
Now to my question(s?).
I'm really interested in learning some socket driven programming,
specifically asyncore/asynchat. I don't need the power or complication of
twisted, but I'm having serious trouble finding any decent tutorials about
asyncore/asychat... so where can I find a good tutuorial?
Thanks for the help,
Wayne
--
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/80d7388b/attachment.htm
From andreas at kostyrka.org Wed Apr 2 14:27:26 2008
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Wed, 02 Apr 2008 14:27:26 +0200
Subject: [Tutor] asyncore/asynchat
In-Reply-To: <333efb450804020507h33afd581va6a4820b5ba711e6@mail.gmail.com>
References: <333efb450804020507h33afd581va6a4820b5ba711e6@mail.gmail.com>
Message-ID: <1207139246.8299.102.camel@localhost>
Well, the source is easy enough to read.
Although I wouldn't call Twisted a complication. If all you want is your
async server Hello World example, asyncore is fine. If you intend to use
the stuff for serious things, one usually starts to reinvent/reimplement
Twisted anyway.
Andreas
Am Mittwoch, den 02.04.2008, 07:07 -0500 schrieb WW:
> Hi, I'm new to the list, and fairly new-ish to python. I'd rate my
> programming experience as beginning-intermediate, and I've had some
> experience with c++ and VBS, and I'm currently a freshman CS major.
>
> Now to my question(s?).
>
> I'm really interested in learning some socket driven programming,
> specifically asyncore/asynchat. I don't need the power or complication
> of twisted, but I'm having serious trouble finding any decent
> tutorials about asyncore/asychat... so where can I find a good
> tutuorial?
>
> Thanks for the help,
> Wayne
>
> --
> 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 at python.org
> http://mail.python.org/mailman/listinfo/tutor
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080402/370a1ff5/attachment.pgp
From kent37 at tds.net Wed Apr 2 15:44:50 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 02 Apr 2008 09:44:50 -0400
Subject: [Tutor] asyncore/asynchat
In-Reply-To: <333efb450804020507h33afd581va6a4820b5ba711e6@mail.gmail.com>
References: <333efb450804020507h33afd581va6a4820b5ba711e6@mail.gmail.com>
Message-ID: <47F38DD2.2090308@tds.net>
WW wrote:
> I'm really interested in learning some socket driven programming,
> specifically asyncore/asynchat. I don't need the power or complication
> of twisted, but I'm having serious trouble finding any decent tutorials
> about asyncore/asychat... so where can I find a good tutuorial?
Googling 'python asyncore' seems to find quite a few resources.
Kent
From mlangford.cs03 at gtalumni.org Wed Apr 2 16:04:04 2008
From: mlangford.cs03 at gtalumni.org (Michael Langford)
Date: Wed, 2 Apr 2008 10:04:04 -0400
Subject: [Tutor] Question about Python ORM
In-Reply-To: <1207135505.8299.91.camel@localhost>
References:
<1207135505.8299.91.camel@localhost>
Message-ID: <82b4f5810804020704x4270b8e3y7848b1c97291d258@mail.gmail.com>
If you do sqlalchemy, I recommend you at least also look at sqlsoup to help
making your mappings easier: http://www.sqlalchemy.org/trac/wiki/SqlSoup
If you don't want to write mappers and you don't need the relational
database, ZODB also works: http://www.zope.org/Products/StandaloneZODB
--Michael
On Wed, Apr 2, 2008 at 7:25 AM, Andreas Kostyrka
wrote:
> There are many as you said yourself. Recommendation: sqlalchemy.org
>
> Andreas
>
> Am Mittwoch, den 02.04.2008, 16:51 +0530 schrieb hiren kumar:
> > Hi,
> >
> > I am very much new to Python and it's available framework.
> >
> > When I search the over net about Python ORM, I found there are so many
> > ORMs available and I was confused between them? I don't understand
> > where to go? :(
> >
> > Can you please tell me something about Python ORM?
> >
> > Regards,
> > Kumar
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/8ca9d1a4/attachment-0001.htm
From bryan.fodness at gmail.com Wed Apr 2 16:44:10 2008
From: bryan.fodness at gmail.com (Bryan Fodness)
Date: Wed, 2 Apr 2008 10:44:10 -0400
Subject: [Tutor] Using split with a backslash
Message-ID:
I have a data pair separated by a backslash. I didn' t think it would see
an end of line if the backslash was inside the quotes.
Can this be done? I don't have a choice in what the separator is.
>>> LeafJawPositions='-42.000000000001\29.800000000001'
>>> LeafJawPositions
'-42.000000000001\x029.800000000001'
>>> x1, x2 = LeafJawPositions.split('\x0')
ValueError: invalid \x escape
>>> x1, x2 = LeafJawPositions.split('\')
SyntaxError: EOL while scanning single-quoted string
>>>
--
"The game of science can accurately be described as a never-ending insult to
human intelligence." - Jo?o Magueijo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/e87b5c02/attachment.htm
From dkuhlman at rexx.com Wed Apr 2 17:40:38 2008
From: dkuhlman at rexx.com (Dave Kuhlman)
Date: Wed, 2 Apr 2008 08:40:38 -0700
Subject: [Tutor] Using split with a backslash
In-Reply-To:
References:
Message-ID: <20080402154037.GA44187@cutter.rexx.com>
On Wed, Apr 02, 2008 at 10:44:10AM -0400, Bryan Fodness wrote:
> I have a data pair separated by a backslash. I didn' t think it would see
> an end of line if the backslash was inside the quotes.
> Can this be done? I don't have a choice in what the separator is.
>
> >>> LeafJawPositions='-42.000000000001\29.800000000001'
> >>> LeafJawPositions
> '-42.000000000001\x029.800000000001'
> >>> x1, x2 = LeafJawPositions.split('\x0')
> ValueError: invalid \x escape
> >>> x1, x2 = LeafJawPositions.split('\')
>
> SyntaxError: EOL while scanning single-quoted string
> >>>
In a literal string, backslash is an escape character. In order to
include a backslash in a literal string, type two backslashes.
Example:
x1, x2 = LeafJawPositions.split('\\')
See http://docs.python.org/ref/strings.html
Another example:
In [1]: a = 'abc\\def\\ghi'
In [2]: len(a)
Out[2]: 11
In [3]: a.split('\')
------------------------------------------------------------
File "", line 1
a.split('\')
^
SyntaxError: EOL while scanning single-quoted string
In [4]: a.split('\\')
Out[4]: ['abc', 'def', 'ghi']
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
From sander.sweers at gmail.com Wed Apr 2 17:57:17 2008
From: sander.sweers at gmail.com (Sander Sweers)
Date: Wed, 2 Apr 2008 08:57:17 -0700
Subject: [Tutor] Using split with a backslash
In-Reply-To:
References:
Message-ID:
On Wed, Apr 2, 2008 at 7:44 AM, Bryan Fodness wrote:
> I have a data pair separated by a backslash. I didn' t think it would see
> an end of line if the backslash was inside the quotes.
The backlash is seen as an escape character.
Try the below, notice the string prefix r and that the backslash is
now escaped by another backslash.
>>> LeafJawPositions=r'-42.000000000001\29.800000000001'
>>> LeafJawPositions
'-42.000000000001\\29.800000000001'
>>> x1, x2 = LeafJawPositions.split('\\')
>>> x1, x2
('-42.000000000001', '29.800000000001')
See http://docs.python.org/ref/strings.html for more info.
Greets
Sander
From alan.gauld at btinternet.com Wed Apr 2 17:57:35 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Wed, 2 Apr 2008 16:57:35 +0100
Subject: [Tutor] Using split with a backslash
References:
Message-ID:
"Bryan Fodness" wrote
> I have a data pair separated by a backslash.
> I didn' t think it would see an end of line if the backslash
> was inside the quotes.
Backslashes don't indicate end of line, they indicate a
continuation of a line. ie they tell Python to *ignore* the
end of line...
> Can this be done? I don't have a choice in what the separator is.
Of course.
>>> LeafJawPositions='-42.000000000001\29.800000000001'
>>> LeafJawPositions
'-42.000000000001\x029.800000000001'
This is reporting \2 as \x02 - which is one character
You need to treat the string as raw characters:
>>> LeafJawPositions=r'-42.000000000001\29.800000000001'
>>> LeafJawPositions
'-42.000000000001\\29.800000000001'
Note the double \.
>>> LeafJawPositions.split('\\')
['-42.000000000001', '29.800000000001']
>>>
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From bryan.fodness at gmail.com Wed Apr 2 18:14:34 2008
From: bryan.fodness at gmail.com (Bryan Fodness)
Date: Wed, 2 Apr 2008 12:14:34 -0400
Subject: [Tutor] Using split with a backslash
In-Reply-To:
References:
Message-ID:
Thanks everyone,
I was trying it this way.
x1, x2 = LeafJawPositions.split(r'\\')
On Wed, Apr 2, 2008 at 11:00 AM, Michael Connors
wrote:
>
> >>> LeafJawPositions='-42.000000000001\29.800000000001'
> > >>> LeafJawPositions
> > '-42.000000000001\x029.800000000001'
> > >>> x1, x2 = LeafJawPositions.split('\x0')
> > ValueError: invalid \x escape
> > >>> x1, x2 = LeafJawPositions.split('\')
> >
> > SyntaxError: EOL while scanning single-quoted string
> > >>>
> >
> > Hi,
> The backslash is used for escaping special characters in a string. In
> order to do what you are trying to do, you would need to escape the
> backslash using a backslash.
> You need to do this in two places in the above code.
> LeafJawPositions='-42.000000000001\\29.800000000001'
>
> and
>
> x1, x2 = LeafJawPositions.split('\\')
>
> http://docs.python.org/ref/strings.html
>
> Regards,
> Michael
>
>
--
"The game of science can accurately be described as a never-ending insult to
human intelligence." - Jo?o Magueijo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/e0b32e4a/attachment.htm
From kent37 at tds.net Wed Apr 2 18:23:30 2008
From: kent37 at tds.net (Kent Johnson)
Date: Wed, 02 Apr 2008 12:23:30 -0400
Subject: [Tutor] Using split with a backslash
In-Reply-To:
References:
Message-ID: <47F3B302.1080007@tds.net>
Bryan Fodness wrote:
> Thanks everyone,
> I was trying it this way.
>
> x1, x2 = LeafJawPositions.split(r'\\')
That is a string containing *two* backslashes.
Kent
From kungfukoi at gmail.com Wed Apr 2 18:44:22 2008
From: kungfukoi at gmail.com (Jeffrey Dates)
Date: Wed, 2 Apr 2008 12:44:22 -0400
Subject: [Tutor] Newb Learning Question
Message-ID: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
Greetings,
I have no previous experience in scripting. Python is my first language...
I'm currently trying to build a logic model for how to 'think' in Python, so
please excuse my ignorance.
Currently, I'm running through some basic 101 tutorials, to wrap my head
around solving problems.
I'm looking for some advice on how to solve the following exercise:
"Write a program that prints the first letter of a string that comes after
'm' in the alphabet."
I hope this is not too elementary.
I do understand basic, basic concepts. iteration, for loops, etc.
Just having trouble with syntax, and how to format my logic.
thank you in advance for any help or examples.
Jeffrey Dates
www.kungfukoi.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/f22a3d36/attachment.htm
From kungfukoi at gmail.com Wed Apr 2 18:50:41 2008
From: kungfukoi at gmail.com (Jeffrey Dates)
Date: Wed, 2 Apr 2008 12:50:41 -0400
Subject: [Tutor] Newb Learning Question
In-Reply-To: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
Message-ID: <1128c3c40804020950x4ebb7200waaccb108405a5597@mail.gmail.com>
Sorry forgot to post what I had so far:
for code in range(ord("a"), ord("z") +1):
if code == ord("m"):
print chr(code +1)
Now, this solves for the first letter after "M", but doesn't do it via a
string....
thanks,
Jeffrey Dates
www.kungfukoi.com
On Wed, Apr 2, 2008 at 12:44 PM, Jeffrey Dates wrote:
> Greetings,
>
> I have no previous experience in scripting. Python is my first
> language...
> I'm currently trying to build a logic model for how to 'think' in Python,
> so please excuse my ignorance.
>
> Currently, I'm running through some basic 101 tutorials, to wrap my head
> around solving problems.
> I'm looking for some advice on how to solve the following exercise:
>
> "Write a program that prints the first letter of a string that comes after
> 'm' in the alphabet."
>
> I hope this is not too elementary.
>
> I do understand basic, basic concepts. iteration, for loops, etc.
> Just having trouble with syntax, and how to format my logic.
>
> thank you in advance for any help or examples.
>
> Jeffrey Dates
> www.kungfukoi.com
>
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/24068fb8/attachment.htm
From steve at alchemy.com Wed Apr 2 19:12:44 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Wed, 2 Apr 2008 10:12:44 -0700
Subject: [Tutor] parse emails as they come in
In-Reply-To:
References: <200803280808.20625.cfuller084@thinkingplanet.net>
<200803312109.49656.cfuller084@thinkingplanet.net>
<20080401211730.GA75799@dragon.alchemy.com>
<47F33328.9050609@alchemy.com>
<47F356DA.4070303@alchemy.com>
Message-ID: <20080402171244.GA38514@dragon.alchemy.com>
On Wed, Apr 02, 2008 at 10:20:41AM +0000, linuxian iandsd wrote:
> well, here is a piece of final script :
>
> #!/usr/bin/python
> #
>
> import sys
>
> b=[]
> while 1:
> data = sys.stdin.readline()
> if data != '\n':
> b.append(data)
> else:
> break
I'd keep working on that loop a bit in accordance with
the advice you've already received.
I'm still not sure why you're not using Python's ability
to iterate over lines of the file directly. I think
it may be simpler to process the data as it comes in
rather than storing it in an array and then go through
it again.
> for i in (0,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16):
> b[i]=b[i].split(':')[1].strip()
> #print b[i]
>
> b[1]=b[1].split(':')
> b[1]=b[1][1]+b[1][2]+b[1][3].strip()
> #print b[1][1]+b[1][2]+b[1][3].strip()
I'd also suggest checking out regular expressions.
You may find a simpler approach to parsing your data
than all this splitting on colons.
> bb=",".join(b)
> print bb
>
> mysqlcmd='insert into webdata field1, field2, field3, field4, field5,
> field6, field7 ..... field17 values (%s)' % bb
Here you have a very common mistake, but an extremely dangerous
one, so I'd like to point it out to you. You're pasting together
strings with commas between them and then pasting that straight
into a SQL statement. You need to be careful to make sure that
the data in bb is valid SQL syntax. In particular, what if any
of the strings contain commas? You'd get extra fields. What if
they contain SQL commands (maybe as a coincidence or maybe not)?
You could make the insert command fail, or corrupt or destroy your
whole database depending on what's in bb.
The good news is that it's really easy to cover that situation.
The MySQL interface libraries support a special kind of statement
where it will handle that for you. You just need to supply the
list of values (not a list you joined up yourself).
Like this:
cursor_object_to_database.execute('insert into webdata field1,
field2, field3, (etc.), field17 values (%s, %s, %s, %s, %s,
(etc.), %s)', *b)
(this is for the MySQLdb module)
Also, how confident are you that the mail format might not be wrong?
Some error checking might be good to add at some point.
>
> On Wed, Apr 2, 2008 at 9:50 AM, Steve Willoughby wrote:
>
> > linuxian iandsd wrote:
> >
> > > well, i don't know how to pipe the file to my script !!
> > >
> >
> > It's how procmail works. Presuming you looked up how to write
> > a procmail rule to save the body of your mail into a file, you
> > should also see right next to it the instructions for piping
> > the message to a program. (It also can be found by a quick
> > Google search, for future reference if you want a quick answer.)
> >
> > You just put a "|" symbol in front of the script name.
> >
> > To save the message to a file, you'd say something like
> >
> > :0:
> > *Subject:.*pattern to look for
> > /home/me/temp_input_file$date$time
> >
> > To pipe it to your script, you'd say something like
> >
> > :0
> > *Subject:.*pattern to look for
> > |/home/me/scriptname
> >
> > For more information see procmailrc(5) and procmailex(5).
> >
> > Your Python script will see the message input on stdin.
> >
> >
> >
> > > On Wed, Apr 2, 2008 at 7:18 AM, Steve Willoughby
> > > wrote:
> > >
> > > linuxian iandsd wrote:
> > > >
> > > > > ok - as i mentioned in my first email i use procmail to put THE BODY
> > > > > of
> > > > >
> > > > all
> > > >
> > > > > incoming mail into a file (that is one per incoming email as i use
> > > > > the
> > > > > variable $date-$time in the name).
> > > > >
> > > > > now this file can contain only one email but it can also contain 2
> > > > > or
> > > > >
> > > > more
> > > >
> > > > > (this happens if for example there is a dns problem in the internet,
> > > > > so
> > > > >
> > > > mail
> > > >
> > > > > can't make it, but once internet recovers from the dns problem mail
> > > > >
> > > > rushes
> > > >
> > > > > in & we may have multiple messages per file. this is also true is i
> > > > > do
> > > > >
> > > > this
> > > >
> > > > Using $date-$time is insufficient since I'll wager a dozen doughnuts
> > > > that the resolution of $time isn't small enough compared to the speed
> > > > messages can arrive.
> > > >
> > > > But as I tried to explain in my previous mail, this is a problem you
> > > > don't have to solve. By choosing to use procmail to dump a file with
> > > > a non-unique name, you create a race condition you then have to deal
> > > > with in your code.
> > > >
> > > > If, on the other hand, you use procmail to _filter_ the message
> > > > through your script, this cannot possibly happen. You'll get an
> > > > invocation of your script per message every time. If you have
> > > > your script directly dump the data into MySQL you never need to
> > > > write any disk files at all.
> > > >
> > > >
> > > >
> > >
> >
> >
--
Steve Willoughby | Using billion-dollar satellites
steve at alchemy.com | to hunt for Tupperware.
From steve at alchemy.com Wed Apr 2 19:14:09 2008
From: steve at alchemy.com (Steve Willoughby)
Date: Wed, 2 Apr 2008 10:14:09 -0700
Subject: [Tutor] Using split with a backslash
In-Reply-To:
References:
Message-ID: <20080402171409.GB38514@dragon.alchemy.com>
On Wed, Apr 02, 2008 at 10:44:10AM -0400, Bryan Fodness wrote:
> I have a data pair separated by a backslash. I didn' t think it would see
> an end of line if the backslash was inside the quotes.
> Can this be done? I don't have a choice in what the separator is.
>
> >>> LeafJawPositions='-42.000000000001\29.800000000001'
> >>> LeafJawPositions
> '-42.000000000001\x029.800000000001'
> >>> x1, x2 = LeafJawPositions.split('\x0')
> ValueError: invalid \x escape
> >>> x1, x2 = LeafJawPositions.split('\')
Try
x1, x2 = LeafJawPositions.split('\\')
--
Steve Willoughby | Using billion-dollar satellites
steve at alchemy.com | to hunt for Tupperware.
From taserian at gmail.com Wed Apr 2 19:28:18 2008
From: taserian at gmail.com (taserian)
Date: Wed, 2 Apr 2008 13:28:18 -0400
Subject: [Tutor] Newb Learning Question
In-Reply-To: <1128c3c40804020950x4ebb7200waaccb108405a5597@mail.gmail.com>
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
<1128c3c40804020950x4ebb7200waaccb108405a5597@mail.gmail.com>
Message-ID: <70dbc4d40804021028n696ebb1cn6921c1a20b7fad5a@mail.gmail.com>
On Wed, Apr 2, 2008 at 12:50 PM, Jeffrey Dates wrote:
> Sorry forgot to post what I had so far:
>
> for code in range(ord("a"), ord("z") +1):
> if code == ord("m"):
> print chr(code +1)
>
> Now, this solves for the first letter after "M", but doesn't do it via a
> string....
>
> thanks,
Let's think about the problem in pseudocode:
If the first letter in the string comes after m in the alphabet, print that
letter.
Otherwise, if the second letter comes after m in the alphabet, print *that*
letter.
etc. etc.
So what you want is to *iterate* through the characters that make up the
string (from start to end) until you find a character that comes after "m".
Your code above seems to *iterate* through all the characters from "a" to
"z", not the characters of a given string.
See if you can fix that first, then we'll talk about the next step.
Tony R.
aka Taser
>
> Jeffrey Dates
> www.kungfukoi.com
>
>
>
>
>
>
> On Wed, Apr 2, 2008 at 12:44 PM, Jeffrey Dates
> wrote:
>
> > Greetings,
> >
> > I have no previous experience in scripting. Python is my first
> > language...
> > I'm currently trying to build a logic model for how to 'think' in
> > Python, so please excuse my ignorance.
> >
> > Currently, I'm running through some basic 101 tutorials, to wrap my head
> > around solving problems.
> > I'm looking for some advice on how to solve the following exercise:
> >
> > "Write a program that prints the first letter of a string that comes
> > after 'm' in the alphabet."
> >
> > I hope this is not too elementary.
> >
> > I do understand basic, basic concepts. iteration, for loops, etc.
> > Just having trouble with syntax, and how to format my logic.
> >
> > thank you in advance for any help or examples.
> >
> > Jeffrey Dates
> > www.kungfukoi.com
> >
> >
> >
> >
> >
> >
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/7da29948/attachment.htm
From bgailer at alum.rpi.edu Wed Apr 2 19:29:27 2008
From: bgailer at alum.rpi.edu (bob gailer)
Date: Wed, 02 Apr 2008 13:29:27 -0400
Subject: [Tutor] Newb Learning Question
In-Reply-To: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
Message-ID: <47F3C277.4010909@alum.rpi.edu>
Jeffrey Dates wrote:
> Greetings,
>
> I have no previous experience in scripting. Python is my first
> language...
> I'm currently trying to build a logic model for how to 'think' in
> Python, so please excuse my ignorance.
>
> Currently, I'm running through some basic 101 tutorials, to wrap my
> head around solving problems.
> I'm looking for some advice on how to solve the following exercise:
>
> "Write a program that prints the first letter of a string that comes
> after 'm' in the alphabet."
>
> what I had so far:
>
> for code in range(ord("a"), ord("z") +1):
> if code == ord("m"):
> print chr(code +1)
>
> Now, this solves for the first letter after "M"
which is NOT what the exercise wants!
Consider "are you ready?". Which character is the first that comes after
'm' in the alphabet."?
BTW did you mean after "m"? Caps and lower case are different.
> , but doesn't do it via a string....
I for one am reluctant to just give an answer. I prefer to lead you to a
solution.
So, I suggest you write a program to:
assign a candidate string to a variable (choose a string that has at
least one letter that "comes after 'm'")
test each character to see if it "comes after 'm'"
print that character
stop
Do as much as you can, and ask more questions.
--
Bob Gailer
919-636-4239 Chapel Hill, NC
From kungfukoi at gmail.com Wed Apr 2 20:26:42 2008
From: kungfukoi at gmail.com (Jeffrey Dates)
Date: Wed, 2 Apr 2008 14:26:42 -0400
Subject: [Tutor] Newb Learning Question
In-Reply-To: <47F3C277.4010909@alum.rpi.edu>
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
<47F3C277.4010909@alum.rpi.edu>
Message-ID: <1128c3c40804021126t5268850cnf644466878730e2@mail.gmail.com>
That's Bob, and Tony, exactly what I'm looking for. ( not the answer, but
the path to it... )
Let me get back to you with my result after I study this a bit.
thanks!!
Jeffrey Dates
www.kungfukoi.com
On undefined, bob gailer wrote:
> Jeffrey Dates wrote:
> > Greetings,
> >
> > I have no previous experience in scripting. Python is my first
> > language...
> > I'm currently trying to build a logic model for how to 'think' in
> > Python, so please excuse my ignorance.
> >
> > Currently, I'm running through some basic 101 tutorials, to wrap my
> > head around solving problems.
> > I'm looking for some advice on how to solve the following exercise:
> >
> > "Write a program that prints the first letter of a string that comes
> > after 'm' in the alphabet."
> >
> > what I had so far:
> >
> > for code in range(ord("a"), ord("z") +1):
> > if code == ord("m"):
> > print chr(code +1)
> >
> > Now, this solves for the first letter after "M"
>
> which is NOT what the exercise wants!
>
> Consider "are you ready?". Which character is the first that comes after
> 'm' in the alphabet."?
>
> BTW did you mean after "m"? Caps and lower case are different.
>
> > , but doesn't do it via a string....
>
> I for one am reluctant to just give an answer. I prefer to lead you to a
> solution.
>
> So, I suggest you write a program to:
> assign a candidate string to a variable (choose a string that has at
> least one letter that "comes after 'm'")
> test each character to see if it "comes after 'm'"
> print that character
> stop
>
> Do as much as you can, and ask more questions.
>
> --
> Bob Gailer
> 919-636-4239 Chapel Hill, NC
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/d292386d/attachment.htm
From washakie at gmail.com Thu Apr 3 01:05:21 2008
From: washakie at gmail.com (John)
Date: Wed, 2 Apr 2008 23:05:21 +0000
Subject: [Tutor] help with slice
In-Reply-To:
References: <15837808.post@talk.nabble.com>
<1204669733.14387.8.camel@localhost> <47CDDA1C.9020402@gmail.com>
Message-ID:
Thanks all for the posts,
I guess I'm thinking in 'matrices' and in a matlab syntax. So I was trying
to get the third element of a list of lists, or lists in a dictionay in
syntax like matlab (yes, I should be using numpy or scipy).
Anyway, Alan's final suggestion (and everyone else's) has helped me better
understand list syntax.
Thanks again.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/b50e3155/attachment.htm
From alan.gauld at btinternet.com Thu Apr 3 01:31:47 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 3 Apr 2008 00:31:47 +0100
Subject: [Tutor] Newb Learning Question
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com><47F3C277.4010909@alum.rpi.edu>
<1128c3c40804021126t5268850cnf644466878730e2@mail.gmail.com>
Message-ID:
"Jeffrey Dates" wrote
> Let me get back to you with my result after I study this a bit.
> thanks!!
One wee tip you might find useful.
To test if a lertter comes after 'm you could
a) create a string with all letters after m
>>> after_m = 'nopqrstuvwxyz'
then test whether your characters were in after_m:
>>> if c in after_m: print c
OR
b) see if the ascii value of your character is bigger
than the ascii value of 'm' And you can check the
ascii value using ord()
There are pros and cons to both approaches.
Pick the one you like best, we can debate
the ideal solution for any given case later...
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From bgailer at alum.rpi.edu Thu Apr 3 02:01:16 2008
From: bgailer at alum.rpi.edu (bob gailer)
Date: Wed, 02 Apr 2008 20:01:16 -0400
Subject: [Tutor] Newb Learning Question
In-Reply-To:
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com><47F3C277.4010909@alum.rpi.edu> <1128c3c40804021126t5268850cnf644466878730e2@mail.gmail.com>
Message-ID: <47F41E4C.6030807@alum.rpi.edu>
Alan Gauld wrote:
> "Jeffrey Dates" wrote
>
>
>> Let me get back to you with my result after I study this a bit.
>> thanks!!
>>
>
> One wee tip you might find useful.
>
> To test if a lertter comes after 'm you could
>
> a) create a string with all letters after m
>
>
>>>> after_m = 'nopqrstuvwxyz'
>>>>
>
> then test whether your characters were in after_m:
>
>
>>>> if c in after_m: print c
>>>>
>
> OR
>
> b) see if the ascii value of your character is bigger
> than the ascii value of 'm' And you can check the
> ascii value using ord()
>
3rd alternative: if c > 'm': print c
> There are pros and cons to both approaches.
> Pick the one you like best, we can debate
> the ideal solution for any given case later...
>
>
--
Bob Gailer
919-636-4239 Chapel Hill, NC
From alan.gauld at btinternet.com Thu Apr 3 09:48:57 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 3 Apr 2008 08:48:57 +0100
Subject: [Tutor] Newb Learning Question
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com><47F3C277.4010909@alum.rpi.edu> <1128c3c40804021126t5268850cnf644466878730e2@mail.gmail.com>
<47F41E4C.6030807@alum.rpi.edu>
Message-ID:
"bob gailer" wrote
> 3rd alternative: if c > 'm': print c
Wow! Amazingly I just assumed you couldn't directly
compare characters with boolean tests. I don't know
why I thought that since it must be possible for string
comparisons, but I did.
You learn something new every day, :-)
Alan G.
From thankyouforthevenom1971 at hotmail.co.uk Thu Apr 3 00:15:10 2008
From: thankyouforthevenom1971 at hotmail.co.uk (dean garrad)
Date: Wed, 2 Apr 2008 23:15:10 +0100
Subject: [Tutor] a pyball python app
Message-ID:
hi there..
im not sure if you can help or you would want to but i fort i may aswell give it a try.
i am currently trying to edit a python app
it is a normal green ball game that comes with python it uses nokia n95 accel to move around.
i have been trying to make more than one ball on the screen at the same time .
do you think it is possable ?
i have attached the script to this e mail and would be greatful for any advice thanks.
dean.
_________________________________________________________________
Amazing prizes every hour with Live Search Big Snap
http://www.bigsnapsearch.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080402/7f2ee39e/attachment.htm
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: trialaccelball.py
Url: http://mail.python.org/pipermail/tutor/attachments/20080402/7f2ee39e/attachment.txt
From kent37 at tds.net Thu Apr 3 13:35:14 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 03 Apr 2008 07:35:14 -0400
Subject: [Tutor] a pyball python app
In-Reply-To:
References:
Message-ID: <47F4C0F2.7060601@tds.net>
dean garrad wrote:
> i am currently trying to edit a python app
>
> it is a normal green ball game that comes with python it uses nokia n95
> accel to move around.
>
> i have been trying to make more than one ball on the screen at the same
> time .
>
> do you think it is possable ?
The attachment seems to be a modified version that moves text around on
the screen, not a ball.
The program uses global variables to hold the state of the moving image,
in particular the lists that hold location and speed. Adding a second
image while keeping the same programming style would involve a lot of
code duplication. What I suggest is to create a Ball object that holds
the location and speed of the ball. The movement code could also go into
the Ball class. Get this working with one ball. Then it should be pretty
easy to add a second ball.
Kent
From kent37 at tds.net Thu Apr 3 14:57:05 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 03 Apr 2008 08:57:05 -0400
Subject: [Tutor] a pyball python app
In-Reply-To:
References:
<47F4C0F2.7060601@tds.net>
Message-ID: <47F4D421.7000007@tds.net>
dean garrad wrote:
> this one is the working version of 1 ball that can move around the
> screen im sorry the other one i sent was a test one ive been trying out..
>
> i cant seam to find it as easy to get it to work with 2 balls on screen.
> anything i try doesnt effect the script.
What have you tried? Do you understand my suggestion?
Kent
PS Please use Reply All to reply to the list
>
>
> when i tes out there is always just 1 ball there the only thing i change
> by accident is the acceleration and gravity of the ball also the size.
From kent37 at tds.net Thu Apr 3 16:16:37 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 03 Apr 2008 10:16:37 -0400
Subject: [Tutor] a pyball python app
In-Reply-To:
References:
<47F4C0F2.7060601@tds.net>
<47F4D421.7000007@tds.net>
Message-ID: <47F4E6C5.8000809@tds.net>
dean garrad wrote:
> i kind of understood what you were saying but not sure how to go by this
> i am still new to python script and learning it as much as i can.
OK. Do you understand how the current script works? If not, what parts
are confusing?
Do you understand object-oriented programming at all (classes)? If not,
you should probably read some tutorials and get at least a basic
understanding.
You could add another ball by brute-force copying of lots of code, or by
making a list of (location, speed) values for each ball, but the code
will end up simpler and easier to understand if you use a class to hold
the parameters for the ball.
Kent
From thankyouforthevenom1971 at hotmail.co.uk Thu Apr 3 16:01:00 2008
From: thankyouforthevenom1971 at hotmail.co.uk (dean garrad)
Date: Thu, 3 Apr 2008 15:01:00 +0100
Subject: [Tutor] a pyball python app
In-Reply-To: <47F4D421.7000007@tds.net>
References:
<47F4C0F2.7060601@tds.net>
<47F4D421.7000007@tds.net>
Message-ID:
i kind of understood what you were saying but not sure how to go by this i am still new to python script and learning it as much as i can.
here is a video of the script in action
http://youtube.com/watch?v=zqZeANFBmis
i did not create the script only trying to modify it. i have permission from the developer to modify.
> Date: Thu, 3 Apr 2008 08:57:05 -0400
> From: kent37 at tds.net
> To: thankyouforthevenom1971 at hotmail.co.uk; tutor at python.org
> Subject: Re: [Tutor] a pyball python app
>
> dean garrad wrote:
>
> > this one is the working version of 1 ball that can move around the
> > screen im sorry the other one i sent was a test one ive been trying out..
> >
> > i cant seam to find it as easy to get it to work with 2 balls on screen.
> > anything i try doesnt effect the script.
>
> What have you tried? Do you understand my suggestion?
>
> Kent
>
> PS Please use Reply All to reply to the list
> >
> >
> > when i tes out there is always just 1 ball there the only thing i change
> > by accident is the acceleration and gravity of the ball also the size.
_________________________________________________________________
Win 100?s of Virgin Experience days with BigSnapSearch.com
http://www.bigsnapsearch.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/ee667259/attachment.htm
From thankyouforthevenom1971 at hotmail.co.uk Thu Apr 3 16:27:16 2008
From: thankyouforthevenom1971 at hotmail.co.uk (dean garrad)
Date: Thu, 3 Apr 2008 15:27:16 +0100
Subject: [Tutor] a pyball python app
In-Reply-To: <47F4E6C5.8000809@tds.net>
References:
<47F4C0F2.7060601@tds.net>
<47F4D421.7000007@tds.net>
<47F4E6C5.8000809@tds.net>
Message-ID:
this is the part im lil confused about to add the extra ball
location=[img.size[0]/2,img.size[1]/2]
speed=[0.,0.]
blobsize=16
xs,ys=img.size[0]-blobsize,img.size[1]-blobsize
acceleration=0.05
friction = 0.993
import time
start_time=time.clock()
n_frames=0
i tried copying but it did nothing do i need to copy it and change something so the python app dont read the same txt twice and jus do nothing?
also on the txt bellow if i add another bal somehow i dotn have to copy or change the txt bellow do i? it should create same value for both balls?
x_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[0])) / 9)
y_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[1])) / 9)
if location[0]>xs:
location[0]=xs-(location[0]-xs)
speed[0]= -x_bounce_factor * speed[0]
speed[1]=0.90*speed[1]
if location[0]<0:
location[0]=-location[0]
speed[0]= -x_bounce_factor * speed[0]
speed[1]=0.90*speed[1]
if location[1]>ys:
location[1]=ys-(location[1]-ys)
speed[0]=0.90*speed[0]
speed[1]= -y_bounce_factor * speed[1]
if location[1]<0:
location[1]=-location[1]
speed[0]=0.90*speed[0]
speed[1]= -y_bounce_factor * speed[1]
im just confused on how to get the programme to add another ball into it and keep everything the same..
i tried changing and copying some of the script but the app jus loads the whole ball script twice and seperate ball on each.
also could you link advise any good tuturials that would help me ive read some on the net but need more help really.
thank you for your time. .
> Date: Thu, 3 Apr 2008 10:16:37 -0400
> From: kent37 at tds.net
> To: thankyouforthevenom1971 at hotmail.co.uk
> CC: tutor at python.org
> Subject: Re: [Tutor] a pyball python app
>
> dean garrad wrote:
> > i kind of understood what you were saying but not sure how to go by this
> > i am still new to python script and learning it as much as i can.
>
> OK. Do you understand how the current script works? If not, what parts
> are confusing?
>
> Do you understand object-oriented programming at all (classes)? If not,
> you should probably read some tutorials and get at least a basic
> understanding.
>
> You could add another ball by brute-force copying of lots of code, or by
> making a list of (location, speed) values for each ball, but the code
> will end up simpler and easier to understand if you use a class to hold
> the parameters for the ball.
>
> Kent
_________________________________________________________________
Win 100?s of Virgin Experience days with BigSnapSearch.com
http://www.bigsnapsearch.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/957557d1/attachment-0001.htm
From kent37 at tds.net Thu Apr 3 16:34:26 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 03 Apr 2008 10:34:26 -0400
Subject: [Tutor] a pyball python app
In-Reply-To:
References:
<47F4C0F2.7060601@tds.net>
<47F4D421.7000007@tds.net>
<47F4E6C5.8000809@tds.net>
Message-ID: <47F4EAF2.6050305@tds.net>
dean garrad wrote:
>
>
> this is the part im lil confused about to add the extra ball
>
> location=[img.size[0]/2,img.size[1]/2]
> speed=[0.,0.]
> i tried copying but it did nothing do i need to copy it and change
> something so the python app dont read the same txt twice and jus do nothing?
If you want to just copy/paste, you will have to copy all the lines
using location and speed and change the copies to something like
location2 and speed2. Of course you should also change the starting
location or speed so the two balls don't draw in the same place!
> also on the txt bellow if i add another bal somehow i dotn have to copy
> or change the txt bellow do i? it should create same value for both balls?
You have to duplicate all the location and speed code, using the new names.
> also could you link advise any good tuturials that would help me ive
> read some on the net but need more help really.
The first two tutorials listed here are popular:
http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
Kent
PS Please subscribe to the list so I don't have to moderate all your
requests through.
From nomb85 at comcast.net Thu Apr 3 17:17:51 2008
From: nomb85 at comcast.net (Nathan McBride)
Date: Thu, 03 Apr 2008 11:17:51 -0400
Subject: [Tutor] socket / over network
In-Reply-To: <47F4EAF2.6050305@tds.net>
References: <47F4C0F2.7060601@tds.net> <47F4D421.7000007@tds.net> <47F4E6C5.8000809@tds.net>
<47F4EAF2.6050305@tds.net>
Message-ID: <47F4F51F.8030309@comcast.net>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hey guys,
I'm pretty tired of the lame backup solution we have at work.
Could anyone point me to a (more or less newbieish) example of how to
have python open a socket on one box and get data from it, then have another
box write to it over the network? I'm having trouble finding something like
this.
Thanks,
Nate
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org
iD8DBQFH9PUf/n+duykW6K8RAvXMAKCE5708Bly/9fzHFZu45cd/d11WGQCdGNcG
PWcbs2jjZXv7b586aNAnSv4=
=9uBW
-----END PGP SIGNATURE-----
From jdates at kungfukoi.com Thu Apr 3 17:21:11 2008
From: jdates at kungfukoi.com (Jeffrey Dates)
Date: Thu, 3 Apr 2008 11:21:11 -0400
Subject: [Tutor] Newb Learning Question
In-Reply-To:
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
<47F3C277.4010909@alum.rpi.edu>
<1128c3c40804021126t5268850cnf644466878730e2@mail.gmail.com>
<47F41E4C.6030807@alum.rpi.edu>
Message-ID: <1128c3c40804030821r1c7bf4cw28cc02ece0d774e1@mail.gmail.com>
>
> > 3rd alternative: if c > 'm': print c
>
after futzing around with interpreting the problem, I ended up with a
solution that utilizes the character comparison.
"Write a program that prints the first letter of a string that comes after
'm' in the alphabet."
s = "this is my string"
for i in s:
if i > 'm':
print i
break
Thanks for all the help everyone. Seems so obvious now.. ;-)
I'm sure I'll be back with some more newb questions in the future. ;-)
jeff.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/8561f826/attachment.htm
From kungfukoi at gmail.com Thu Apr 3 17:32:54 2008
From: kungfukoi at gmail.com (Jeffrey Dates)
Date: Thu, 3 Apr 2008 11:32:54 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
Message-ID: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
Hello,
So as I'm starting to get into writing some scripts, I'm looking for
recommendations for a nifty script editor. Ideally a freeware/shareware
solution until I can justify a purchase of something more beefy.
Currently I'm using PSPad, however it's pretty dumb and doesn't recognize
Python context. Which, I suppose is fine, but would be nice if there was
one. Especially since I'm learning.
My run time environment is IDLE.
Any thoughts or preferences would be appreciated.
thanks!
Jeffrey Dates
www.kungfukoi.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/a52832c3/attachment.htm
From alan.gauld at btinternet.com Thu Apr 3 17:44:34 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 3 Apr 2008 16:44:34 +0100
Subject: [Tutor] socket / over network
References: <47F4C0F2.7060601@tds.net> <47F4D421.7000007@tds.net> <47F4E6C5.8000809@tds.net> <47F4EAF2.6050305@tds.net>
<47F4F51F.8030309@comcast.net>
Message-ID:
"Nathan McBride" wrote
Hi Nathan,
Please don't reply to an existing message to start a new discussion.
It messes up those of us using threaded mail/news readers and
increases the likelihood that your message will be missed.
> I'm pretty tired of the lame backup solution we have at work.
> Could anyone point me to a (more or less newbieish) example of how
> to
> have python open a socket on one box and get data from it, then have
> another
> box write to it over the network?
For a very simple example of using a socket you could try the
Network Programming topic in my tutorial.
There is also a HowTo or Topic guide on the Python web site
that gives a more detailed example.
That having been said, backups are usually best done using
OS tools or if you must roll your own then using ftp or similar
as a file transfer mechanism rather than trying to send a
bytestream over a socket. ftp can handle broken connections
etc more easily. Detecting and fixing errors over a socket
stream is non trivial and for backups is pretty much essential!!
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From alan.gauld at btinternet.com Thu Apr 3 17:57:10 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Thu, 3 Apr 2008 16:57:10 +0100
Subject: [Tutor] Which Python Script Editor of Choice?
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
Message-ID:
"Jeffrey Dates" wrote
> So as I'm starting to get into writing some scripts, I'm looking for
> recommendations for a nifty script editor. Ideally a
> freeware/shareware
> solution until I can justify a purchase of something more beefy.
editor choice is a sensitive topic for programmers and
tends to lead to religious wars.
> Currently I'm using PSPad, however it's pretty dumb and doesn't
> recognize
> Python context. Which, I suppose is fine, but would be nice if
> there was
> one. Especially since I'm learning.
If you are on Windows then the Pythonwin editor is pretty good.
Or for a simple editor you can use Scite which is the same editor
engine as Pythonwin but includes multiple tabbed panes. But
doesn't include an interactive shell.
At the other end of the scale you can install PyDev into the
eclipse editor which is a good solution if you already use
Eclipse for anything else.
emacs and vim can both be made Python aware too.
And there are lots of others that each has their followers.
SPE and Ala Mode(comes with wxPython) are others that
I personally tried and found OK.
My normal tools are:
Pythonwin for short coding sessions or when using the >>>
prompt a lot.
For longer coding sesssions I use the 3 window approach:
vijm for editing, a DOS(Cygwin) window for running the code and
another Cygwin window running the Python >>> prompt.
And Alt-Tab to switch between them.
> My run time environment is IDLE.
But IDLE should never be your main run time environment.
It is an IDE for developing code but you should run the code
under the interpreter within the OS, you will generally get better
(more predicatable!) results that way. The IDLE editor is
OK too of course but I assumed you didn't want it for
some reason?
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From bgailer at alum.rpi.edu Thu Apr 3 18:03:00 2008
From: bgailer at alum.rpi.edu (bob gailer)
Date: Thu, 03 Apr 2008 12:03:00 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
Message-ID: <47F4FFB4.8050001@alum.rpi.edu>
Jeffrey Dates wrote:
> Hello,
>
> So as I'm starting to get into writing some scripts, I'm looking for
> recommendations for a nifty script editor. Ideally a
> freeware/shareware solution until I can justify a purchase of
> something more beefy.
I use Python for Windows and really like it. It is free.
http://sourceforge.net/projects/pywin32/
>
> Currently I'm using PSPad, however it's pretty dumb and doesn't
> recognize Python context.
I went to the PSPad site, but found no way to download the editor. Am I
missing something?
> My run time environment is IDLE.
It is more accurate to say "My development environment is IDLE." The
underlying Python interpreter is the runtime.
--
Bob Gailer
919-636-4239 Chapel Hill, NC
From bgailer at alum.rpi.edu Thu Apr 3 18:07:05 2008
From: bgailer at alum.rpi.edu (Bob Gailer)
Date: Thu, 03 Apr 2008 12:07:05 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
Message-ID: <47F500A9.4080106@alum.rpi.edu>
[snip]
> I went to the PSPad site, but found no way to download the editor. Am
> I missing something?
Ignore that. Something on the home page did not display correctly.
Refresh fixed that.
--
Bob Gailer
919-636-4239 Chapel Hill, NC
From andreas at kostyrka.org Thu Apr 3 18:15:09 2008
From: andreas at kostyrka.org (Andreas Kostyrka)
Date: Thu, 03 Apr 2008 18:15:09 +0200
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To:
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
Message-ID: <1207239309.19833.0.camel@localhost>
Eric and SPE are also nice.
The good thing here is that the majority of IDEs for Python are free.
Andreas
Am Donnerstag, den 03.04.2008, 16:57 +0100 schrieb Alan Gauld:
> "Jeffrey Dates" wrote
>
> > So as I'm starting to get into writing some scripts, I'm looking for
> > recommendations for a nifty script editor. Ideally a
> > freeware/shareware
> > solution until I can justify a purchase of something more beefy.
>
> editor choice is a sensitive topic for programmers and
> tends to lead to religious wars.
>
> > Currently I'm using PSPad, however it's pretty dumb and doesn't
> > recognize
> > Python context. Which, I suppose is fine, but would be nice if
> > there was
> > one. Especially since I'm learning.
>
> If you are on Windows then the Pythonwin editor is pretty good.
>
> Or for a simple editor you can use Scite which is the same editor
> engine as Pythonwin but includes multiple tabbed panes. But
> doesn't include an interactive shell.
>
> At the other end of the scale you can install PyDev into the
> eclipse editor which is a good solution if you already use
> Eclipse for anything else.
>
> emacs and vim can both be made Python aware too.
>
> And there are lots of others that each has their followers.
> SPE and Ala Mode(comes with wxPython) are others that
> I personally tried and found OK.
>
> My normal tools are:
> Pythonwin for short coding sessions or when using the >>>
> prompt a lot.
> For longer coding sesssions I use the 3 window approach:
> vijm for editing, a DOS(Cygwin) window for running the code and
> another Cygwin window running the Python >>> prompt.
> And Alt-Tab to switch between them.
>
> > My run time environment is IDLE.
>
> But IDLE should never be your main run time environment.
> It is an IDE for developing code but you should run the code
> under the interpreter within the OS, you will generally get better
> (more predicatable!) results that way. The IDLE editor is
> OK too of course but I assumed you didn't want it for
> some reason?
>
> HTH,
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
Url : http://mail.python.org/pipermail/tutor/attachments/20080403/f4fc0892/attachment-0001.pgp
From jdates at kungfukoi.com Thu Apr 3 18:19:59 2008
From: jdates at kungfukoi.com (Jeffrey Dates)
Date: Thu, 3 Apr 2008 12:19:59 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <1207239309.19833.0.camel@localhost>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
<1207239309.19833.0.camel@localhost>
Message-ID: <1128c3c40804030919j5a74c56eo6c5cae5def782e38@mail.gmail.com>
Ah thanks guy!!
Yeah, I guess I didn't mean which is the 'best'...
Just some options.
Thanks, I'll check out the ones you listed!
I'm on Windows btw.
Jeffrey Dates
www.kungfukoi.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/1b4444d6/attachment.htm
From tonytraductor at linguasos.org Thu Apr 3 18:44:17 2008
From: tonytraductor at linguasos.org (Anthony Baldwin)
Date: Thu, 03 Apr 2008 12:44:17 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <1207239309.19833.0.camel@localhost>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
<1207239309.19833.0.camel@localhost>
Message-ID: <47F50961.5040909@linguasos.org>
Andreas Kostyrka wrote:
> Eric and SPE are also nice.
>
> The good thing here is that the majority of IDEs for Python are free.
>
> Andreas
>
> Am Donnerstag, den 03.04.2008, 16:57 +0100 schrieb Alan Gauld:
>
>> "Jeffrey Dates" wrote
>>
>>
>>> So as I'm starting to get into writing some scripts, I'm looking for
>>> recommendations for a nifty script editor. Ideally a
>>> freeware/shareware
>>> solution until I can justify a purchase of something more beefy.
>>>
>> editor choice is a sensitive topic for programmers and
>> tends to lead to religious wars.
>>
>>
>>
I use TickleText (http://sourceforge.net/projects/tickletext/ )
It doesn't have python syntax highlighting though.
I'm really just starting with python, and mostly hack tcl.tk,
in which TickleText is written.
It's good for writing html and LaTeX, and other stuff, too, and has
some other useful features.
It's certainly not as fat and bloated as Emacs (hehe...Emacs is cool,
really).
I used to use medit or kate.
But then I made Tickle Text.
Kdevelop is nice if you want a full IDE that does recognize python syntax.
And, of course, if you are using Linux. I don't use KDE (use fluxbox), but
I like some of these KDE tools.
/tony
--
Anthony Baldwin
http://www.BaldwinLinguas.com
Translation & Interpreting
http://www.TransProCalc.org
Free translation project mgmt software
From pylinuxian at gmail.com Thu Apr 3 18:52:06 2008
From: pylinuxian at gmail.com (linuxian iandsd)
Date: Thu, 3 Apr 2008 16:52:06 +0000
Subject: [Tutor] socket / over network
In-Reply-To:
References:
<47F4D421.7000007@tds.net>
<47F4E6C5.8000809@tds.net>
<47F4EAF2.6050305@tds.net> <47F4F51F.8030309@comcast.net>
Message-ID:
re-inventing the wheel ?
http://www.howtoforge.com/linux_backuppc
>
>
> On Thu, Apr 3, 2008 at 3:44 PM, Alan Gauld
> wrote:
>
> > "Nathan McBride" wrote
> >
> > Hi Nathan,
> >
> > Please don't reply to an existing message to start a new discussion.
> > It messes up those of us using threaded mail/news readers and
> > increases the likelihood that your message will be missed.
> >
> > > I'm pretty tired of the lame backup solution we have at work.
> > > Could anyone point me to a (more or less newbieish) example of how
> > > to
> > > have python open a socket on one box and get data from it, then have
> > > another
> > > box write to it over the network?
> >
> > For a very simple example of using a socket you could try the
> > Network Programming topic in my tutorial.
> >
> > There is also a HowTo or Topic guide on the Python web site
> > that gives a more detailed example.
> >
> > That having been said, backups are usually best done using
> > OS tools or if you must roll your own then using ftp or similar
> > as a file transfer mechanism rather than trying to send a
> > bytestream over a socket. ftp can handle broken connections
> > etc more easily. Detecting and fixing errors over a socket
> > stream is non trivial and for backups is pretty much essential!!
> >
> > --
> > Alan Gauld
> > Author of the Learn to Program web site
> > http://www.freenetpages.co.uk/hp/alan.gauld
> >
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/4d201858/attachment.htm
From thankyouforthevenom1971 at hotmail.co.uk Thu Apr 3 19:04:10 2008
From: thankyouforthevenom1971 at hotmail.co.uk (dean garrad)
Date: Thu, 3 Apr 2008 18:04:10 +0100
Subject: [Tutor] a pyball python app
In-Reply-To: <47F4EAF2.6050305@tds.net>
References:
<47F4C0F2.7060601@tds.net>
<47F4D421.7000007@tds.net>
<47F4E6C5.8000809@tds.net>
<47F4EAF2.6050305@tds.net>
Message-ID:
hi i signed onto the site it asked me to. :).
can i talk to ya now more ?
im not sure if i am in wrong place to send e mail to you still
i still ahving problems with the ball script this is the script at the moment how it stands with 1 ball working fine and i have been trying to add another ball to the script.
i coppied the txt and added a location2 aswell as location. but it didnt seam to work :S
import appuifw
from graphics import *
import e32
import sensor
class SensorConnection(object):
delta = []
def __init__(self):
"""Connect to the sensor."""
sens = sensor.sensors()['AccSensor']
self.s = sensor.Sensor(sens['id'], sens['category'])
self.s.connect(self.callme)
def callme(self, state):
self.delta = []
for key in ['data_1', 'data_2', 'data_3']:
val = state[key]
self.delta.append(int(val + 40)/80)
def cleanup(self):
"""Cleanup after yourself. *Must be called* before exiting."""
self.s.disconnect()
sense_conn = SensorConnection()
appuifw.app.screen='full'
img=None
def handle_redraw(rect):
if img:
canvas.blit(img)
appuifw.app.body=canvas=appuifw.Canvas(
redraw_callback=handle_redraw)
img=Image.new(canvas.size)
running=1
def quit():
global running
running=0
appuifw.app.exit_key_handler=quit
location=[img.size[0]/2,img.size[1]/2]
speed=[0.,0.]
blobsize=16
xs,ys=img.size[0]-blobsize,img.size[1]-blobsize
acceleration=0.05
friction = 0.993
import time
start_time=time.clock()
n_frames=0
# To speed things up, we prerender the text.
labeltext=u'Tilt the phone to move'
textrect=img.measure_text(labeltext, font='normal')[0]
text_img=Image.new((textrect[2]-textrect[0],textrect[3]-textrect[1]))
text_img.clear(0)
text_img.text((-textrect[0],-textrect[1]),labeltext,fill=0xffffff,font='normal')
while running:
img.clear(0)
img.blit(text_img, (0,0))
img.point((location[0]+blobsize/2,location[1]+blobsize/2),
0x00ff00,width=blobsize)
handle_redraw(())
e32.ao_yield()
e32.reset_inactivity()
speed[0]*=friction
speed[1]*=friction
location[0]+=speed[0]
location[1]+=speed[1]
n_frames+=1
if not sense_conn: continue
if not len(sense_conn.delta): continue
x_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[0])) / 9)
y_bounce_factor = .8 * (1 - min(6,abs(sense_conn.delta[1])) / 9)
if location[0]>xs:
location[0]=xs-(location[0]-xs)
speed[0]= -x_bounce_factor * speed[0]
speed[1]=0.90*speed[1]
if location[0]<0:
location[0]=-location[0]
speed[0]= -x_bounce_factor * speed[0]
speed[1]=0.90*speed[1]
if location[1]>ys:
location[1]=ys-(location[1]-ys)
speed[0]=0.90*speed[0]
speed[1]= -y_bounce_factor * speed[1]
if location[1]<0:
location[1]=-location[1]
speed[0]=0.90*speed[0]
speed[1]= -y_bounce_factor * speed[1]
speed[0] -= (sense_conn.delta[1]) * acceleration
speed[1] -= (sense_conn.delta[0]) * acceleration
speed[0] = max(min(xs / 2, speed[0]), -xs/2)
speed[1] = max(min(ys / 2, speed[1]), -ys/2)
end_time=time.clock()
total=end_time-start_time
sense_conn.cleanup()
print "%d frames, %f seconds, %f FPS, %f ms/frame."%(n_frames,total,
n_frames/total,
total/n_frames*1000.)
> Date: Thu, 3 Apr 2008 10:34:26 -0400
> From: kent37 at tds.net
> To: thankyouforthevenom1971 at hotmail.co.uk
> CC: tutor at python.org
> Subject: Re: [Tutor] a pyball python app
>
> dean garrad wrote:
> >
> >
> > this is the part im lil confused about to add the extra ball
> >
> > location=[img.size[0]/2,img.size[1]/2]
> > speed=[0.,0.]
>
> > i tried copying but it did nothing do i need to copy it and change
> > something so the python app dont read the same txt twice and jus do nothing?
>
> If you want to just copy/paste, you will have to copy all the lines
> using location and speed and change the copies to something like
> location2 and speed2. Of course you should also change the starting
> location or speed so the two balls don't draw in the same place!
>
> > also on the txt bellow if i add another bal somehow i dotn have to copy
> > or change the txt bellow do i? it should create same value for both balls?
>
> You have to duplicate all the location and speed code, using the new names.
>
> > also could you link advise any good tuturials that would help me ive
> > read some on the net but need more help really.
>
> The first two tutorials listed here are popular:
> http://wiki.python.org/moin/BeginnersGuide/NonProgrammers
>
> Kent
>
> PS Please subscribe to the list so I don't have to moderate all your
> requests through.
_________________________________________________________________
The next generation of Windows Live is here
http://www.windowslive.co.uk/get-live
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/90acc349/attachment.htm
From mlangford.cs03 at gtalumni.org Thu Apr 3 19:15:34 2008
From: mlangford.cs03 at gtalumni.org (Michael Langford)
Date: Thu, 3 Apr 2008 13:15:34 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
Message-ID: <82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
Asking a programmer which editor to use is like asking which religion is
best.
I use VIM and IPython and shell scripts (I mostly program on windows, but
sometimes on Linux as well).
There are several options. I'm considering looking into PIDA, which is a
"IDE you make from tools you already use" but haven't had time to try to
check it out on windows.
Eric4 and Wingware are both very fully developed. Komodo also often gets
props from the "IDE People" I've known.
Other "IDE" choices go as follow, DrPython, pyCrust, emacs, VIM (has IDE
addons), IronPython/VisualStudio, Boa Constrictor, and Eclipse.
I do often suggest to people who are just starting out: Learn to program
without an IDE, then use one after 6 mo/a year.
Many people who go this way, program with or without one just fine. Those
who start right away always using IDE's can just plain die when they hit an
environment where they don't have one (due to time, money, location, or
whatever).
Btw, if people know of good IDE's other than PIDA that are free, run on
windows and linux and allow use of VIM as the editor, please let me know.
--Michael
On Thu, Apr 3, 2008 at 11:32 AM, Jeffrey Dates wrote:
> Hello,
>
> So as I'm starting to get into writing some scripts, I'm looking for
> recommendations for a nifty script editor. Ideally a freeware/shareware
> solution until I can justify a purchase of something more beefy.
>
> Currently I'm using PSPad, however it's pretty dumb and doesn't recognize
> Python context. Which, I suppose is fine, but would be nice if there was
> one. Especially since I'm learning.
>
> My run time environment is IDLE.
>
> Any thoughts or preferences would be appreciated.
> thanks!
>
> Jeffrey Dates
> www.kungfukoi.com
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/981df247/attachment-0001.htm
From sirgnip at gmail.com Thu Apr 3 19:28:52 2008
From: sirgnip at gmail.com (Scott Nelson)
Date: Thu, 3 Apr 2008 12:28:52 -0500
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
<82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
Message-ID: <2682ac9b0804031028w36668405hc581166a4be12f68@mail.gmail.com>
>
> Komodo also often gets props from the "IDE People" I've known.
To throw another one into the mix, ActiveState has a free/open source
version of its Komodo IDE called "Komodo Edit". I downloaded it and played
with it for a few minutes awhile ago. Seems pretty slick. Anyone have any
first hand experience with this one? It also supports more than just Python
(also does Perl, PHP, Ruby, Rails, etc.)
http://www.activestate.com/Products/komodo_ide/komodo_edit.mhtml
(FWIW, most of the time, I use PythonWin to edit code and a command prompt
to run scripts)
> Btw, if people know of good IDE's other than PIDA that are free, run on
windows and linux and allow use of VIM as the editor, please let me know.
Looking at Komodo Edit's page, it supports Win/Mac/Linux, has "Vi
emulation", and is free (not crippled in any way that I know of. It just
has a smaller feature set when compared to the full Komodo).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/a5c8e1dd/attachment.htm
From kent37 at tds.net Thu Apr 3 20:16:02 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 03 Apr 2008 14:16:02 -0400
Subject: [Tutor] a pyball python app
In-Reply-To:
References:
<47F4C0F2.7060601@tds.net>
<47F4D421.7000007@tds.net>
<47F4E6C5.8000809@tds.net>
<47F4EAF2.6050305@tds.net>
Message-ID: <47F51EE2.5020401@tds.net>
dean garrad wrote:
> i still ahving problems with the ball script this is the script at the
> moment how it stands with 1 ball working fine and i have been trying to
> add another ball to the script.
>
> i coppied the txt and added a location2 aswell as location. but it didnt
> seam to work :S
I don't see where you added location2.
I think you are over your head with this project. I recommend you spend
some time with a tutorial and some simpler programs, then come back to
this one. Perhaps one goal would be to understand how your current
program works.
Kent
From sander.sweers at gmail.com Thu Apr 3 20:17:05 2008
From: sander.sweers at gmail.com (Sander Sweers)
Date: Thu, 3 Apr 2008 11:17:05 -0700
Subject: [Tutor] Newb Learning Question
In-Reply-To:
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
<47F3C277.4010909@alum.rpi.edu>
<1128c3c40804021126t5268850cnf644466878730e2@mail.gmail.com>
<47F41E4C.6030807@alum.rpi.edu>
<1128c3c40804030821r1c7bf4cw28cc02ece0d774e1@mail.gmail.com>
Message-ID:
Should be replying to the list....Sorry :(
On Thu, Apr 3, 2008 at 11:14 AM, Sander Sweers wrote:
> On Thu, Apr 3, 2008 at 8:21 AM, Jeffrey Dates wrote:
> > > > 3rd alternative: if c > 'm': print c
>
>
>
>
> > "Write a program that prints the first letter of a string that comes after
> > 'm' in the alphabet."
> >
> > s = "this is my string"
> > for i in s:
> > if i > 'm':
> > print i
> > break
>
> One potential problem you will have is with upper case letters.
>
> >>> 'N' > 'm'
> False
>
> To make input all lower case use .lower()
>
> >>> 'N'.lower() > 'm'
> True
>
> Greets
> Sander
>
From jdates at kungfukoi.com Thu Apr 3 20:37:50 2008
From: jdates at kungfukoi.com (Jeffrey Dates)
Date: Thu, 3 Apr 2008 14:37:50 -0400
Subject: [Tutor] Newb Learning Question
In-Reply-To:
References: <1128c3c40804020944r35be5459p3d4752002c6fd8c3@mail.gmail.com>
<47F3C277.4010909@alum.rpi.edu>
<1128c3c40804021126t5268850cnf644466878730e2@mail.gmail.com>
<47F41E4C.6030807@alum.rpi.edu>
<1128c3c40804030821r1c7bf4cw28cc02ece0d774e1@mail.gmail.com>
Message-ID: <1128c3c40804031137y2e6dd078ie46b6896941f238f@mail.gmail.com>
Exellent suggestion!
thanks!
On Thu, Apr 3, 2008 at 2:17 PM, Sander Sweers
wrote:
> Should be replying to the list....Sorry :(
>
> On Thu, Apr 3, 2008 at 11:14 AM, Sander Sweers
> wrote:
> > On Thu, Apr 3, 2008 at 8:21 AM, Jeffrey Dates
> wrote:
> > > > > 3rd alternative: if c > 'm': print c
> >
> >
> >
> >
> > > "Write a program that prints the first letter of a string that comes
> after
> > > 'm' in the alphabet."
> > >
> > > s = "this is my string"
> > > for i in s:
> > > if i > 'm':
> > > print i
> > > break
> >
> > One potential problem you will have is with upper case letters.
> >
> > >>> 'N' > 'm'
> > False
> >
> > To make input all lower case use .lower()
> >
> > >>> 'N'.lower() > 'm'
> > True
> >
> > Greets
> > Sander
> >
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/fb60fdbc/attachment.htm
From srilyk at gmail.com Thu Apr 3 20:40:10 2008
From: srilyk at gmail.com (W W)
Date: Thu, 3 Apr 2008 13:40:10 -0500
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
<82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
Message-ID: <333efb450804031140l10b3fb40ge82732967b019649@mail.gmail.com>
On Thu, Apr 3, 2008 at 12:15 PM, Michael Langford
wrote:
> Many people who go this way, program with or without one just fine. Those who start right away always using IDE's can just plain die when they hit an environment where they don't have one (due to time, money, location, or whatever).
>
> Btw, if people know of good IDE's other than PIDA that are free, run on windows and linux and allow use of VIM as the editor, please let me know.
I personally use VIM/vi as my editor. The best thing about using VIM
(at least when it comes to testing) is the ability to run command line
arguments from vim.
:!python hand_grenade.py
would run your script (assuming you started editing in whatever
directory). Auto complete (the use of works too. I've never used
an IDE aside from the MS Visual Studio for our CS I class - and I find
it to be horrible overkill, confusing, and less powerful than vim and
g++ from the command line under ubuntu.
I suppose my method isn't an IDE, but it works for me (and so far I
don't see any reason to change, if I need to edit multiple files at a
time I can :split windows, yada yada).
Find whatever suits you, and good luck in the hunt
-Wayne
From srilyk at gmail.com Thu Apr 3 20:46:29 2008
From: srilyk at gmail.com (W W)
Date: Thu, 3 Apr 2008 13:46:29 -0500
Subject: [Tutor] a pyball python app
In-Reply-To: <47F51EE2.5020401@tds.net>
References:
<47F4C0F2.7060601@tds.net>
<47F4D421.7000007@tds.net>
<47F4E6C5.8000809@tds.net>
<47F4EAF2.6050305@tds.net>
<47F51EE2.5020401@tds.net>
Message-ID: <333efb450804031146g530feb2drbb3fd1c713c4eedf@mail.gmail.com>
Dean,
Here's a tutorial/book that you should check out:
http://www.greenteapress.com/thinkpython/
How to Think Like a (Python) Programmer by Allen B. Downey
He generously has a free PDF to download, and the book makes use of
some code - swampy.py
I think if you 1) Read the book and try the examples, and at least try
/some/ of the assignments, and 2) Examine the source code of the
swampy program, you'll learn how to do exactly what you want - create
two different balls (or technically, as many as you'd like/the phone
will run).
Good luck!
-Wayne
On Thu, Apr 3, 2008 at 1:16 PM, Kent Johnson wrote:
> dean garrad wrote:
>
> > i still ahving problems with the ball script this is the script at the
> > moment how it stands with 1 ball working fine and i have been trying to
> > add another ball to the script.
> >
> > i coppied the txt and added a location2 aswell as location. but it didnt
> > seam to work :S
>
> I don't see where you added location2.
>
> I think you are over your head with this project. I recommend you spend
> some time with a tutorial and some simpler programs, then come back to
> this one. Perhaps one goal would be to understand how your current
> program works.
>
> Kent
>
>
> _______________________________________________
> Tutor maillist - Tutor at 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
From dkuhlman at rexx.com Thu Apr 3 21:46:45 2008
From: dkuhlman at rexx.com (Dave Kuhlman)
Date: Thu, 3 Apr 2008 12:46:45 -0700
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
Message-ID: <20080403194645.GA30997@cutter.rexx.com>
On Thu, Apr 03, 2008 at 11:32:54AM -0400, Jeffrey Dates wrote:
> Hello,
>
> So as I'm starting to get into writing some scripts, I'm looking for
> recommendations for a nifty script editor. Ideally a freeware/shareware
> solution until I can justify a purchase of something more beefy.
>
> Currently I'm using PSPad, however it's pretty dumb and doesn't recognize
> Python context. Which, I suppose is fine, but would be nice if there was
> one. Especially since I'm learning.
>
If you are looking for text editors, this page will give you more
choices than you want:
http://en.wikipedia.org/wiki/Comparison_of_text_editors
My favorites are:
- Jed
- Emacs
- SciTE
- Jedit (but only if you have lots of memory)
Jed, Emacs, and SciTE are scriptable. SciTe, perhaps, is not.
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
From kent37 at tds.net Thu Apr 3 22:05:28 2008
From: kent37 at tds.net (Kent Johnson)
Date: Thu, 03 Apr 2008 16:05:28 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <20080403194645.GA30997@cutter.rexx.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
<20080403194645.GA30997@cutter.rexx.com>
Message-ID: <47F53888.6030708@tds.net>
Dave Kuhlman wrote:
> If you are looking for text editors, this page will give you more
> choices than you want:
>
> http://en.wikipedia.org/wiki/Comparison_of_text_editors
And this:
http://wiki.python.org/moin/PythonEditors
When I worked on Windows I used TextPad, it's inexpensive but not free.
Kent
From mlangford.cs03 at gtalumni.org Thu Apr 3 23:12:15 2008
From: mlangford.cs03 at gtalumni.org (Michael Langford)
Date: Thu, 3 Apr 2008 17:12:15 -0400
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <333efb450804031140l10b3fb40ge82732967b019649@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
<82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
<333efb450804031140l10b3fb40ge82732967b019649@mail.gmail.com>
Message-ID: <82b4f5810804031412l5368974eqfd7217d7ae643193@mail.gmail.com>
When you have you use Visual Studio, I suggest using the beautiful and
wonder ViEmu. Best $90 I ever spent:
http://www.viemu.com/
On Thu, Apr 3, 2008 at 2:40 PM, W W wrote:
> On Thu, Apr 3, 2008 at 12:15 PM, Michael Langford
> wrote:
> > Many people who go this way, program with or without one just fine.
> Those who start right away always using IDE's can just plain die when they
> hit an environment where they don't have one (due to time, money, location,
> or whatever).
> >
> > Btw, if people know of good IDE's other than PIDA that are free, run on
> windows and linux and allow use of VIM as the editor, please let me know.
>
> I personally use VIM/vi as my editor. The best thing about using VIM
> (at least when it comes to testing) is the ability to run command line
> arguments from vim.
>
> :!python hand_grenade.py
>
> would run your script (assuming you started editing in whatever
> directory). Auto complete (the use of works too. I've never used
> an IDE aside from the MS Visual Studio for our CS I class - and I find
> it to be horrible overkill, confusing, and less powerful than vim and
> g++ from the command line under ubuntu.
>
> I suppose my method isn't an IDE, but it works for me (and so far I
> don't see any reason to change, if I need to edit multiple files at a
> time I can :split windows, yada yada).
>
> Find whatever suits you, and good luck in the hunt
> -Wayne
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
--
Michael Langford
Phone: 404-386-0495
Consulting: http://www.RowdyLabs.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080403/771e88b5/attachment-0001.htm
From oltarasenko at gmail.com Fri Apr 4 10:03:14 2008
From: oltarasenko at gmail.com (Oleg Oltar)
Date: Fri, 4 Apr 2008 11:03:14 +0300
Subject: [Tutor] Unittest traceback
Message-ID:
Hi!
I am trying to use unittest in python first time. But have a strange
traceback each time I run my sample tests.
Can you please explain why I have it. No info about it in the doc.
e.g. the code is
import unittest
import squaren
class TestCases(unittest.TestCase):
def setUp(self):
pass
def testsmall(self):
self.assertEqual(True, True)
if __name__ == '__main__':
unittest.main()
And the traceback is
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
Traceback (most recent call last):
File "/tmp/py359hJx", line 14, in
unittest.main()
File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
self.runTests()
File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
sys.exit(not result.wasSuccessful())
SystemExit: False
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/3eafad1c/attachment.htm
From kent37 at tds.net Fri Apr 4 13:36:16 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 04 Apr 2008 07:36:16 -0400
Subject: [Tutor] Unittest traceback
In-Reply-To:
References:
Message-ID: <47F612B0.7020907@tds.net>
Oleg Oltar wrote:
> Hi!
>
> I am trying to use unittest in python first time. But have a strange
> traceback each time I run my sample tests.
How are you running the test? My guess is that you are running it in an
IDE or something that shows the normal system exit exception.
Calling sys.exit() raises the SystemExit exception with a result code.
Normally this is not shown by the runner.
In Python False == 0 so your program is exiting normally with a code of
0 (no error). It is probably the program runner that is showing the
traceback.
Try running the program from the command line.
Kent
> Can you please explain why I have it. No info about it in the doc.
> e.g. the code is
>
> import unittest
> import squaren
>
> class TestCases(unittest.TestCase):
> def setUp(self):
> pass
>
> def testsmall(self):
> self.assertEqual(True, True)
>
>
>
> if __name__ == '__main__':
> unittest.main()
>
> And the traceback is
>
> ----------------------------------------------------------------------
> Ran 1 test in 0.000s
>
> OK
> Traceback (most recent call last):
> File "/tmp/py359hJx", line 14, in
> unittest.main()
> File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
> self.runTests()
> File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
> sys.exit(not result.wasSuccessful())
> SystemExit: False
From oltarasenko at gmail.com Fri Apr 4 13:50:12 2008
From: oltarasenko at gmail.com (Oleg Oltar)
Date: Fri, 4 Apr 2008 14:50:12 +0300
Subject: [Tutor] Fwd: Unittest traceback
In-Reply-To:
References:
<47F612B0.7020907@tds.net>
Message-ID:
---------- Forwarded message ----------
From: Oleg Oltar
Date: Fri, Apr 4, 2008 at 2:49 PM
Subject: Re: [Tutor] Unittest traceback
To: Kent Johnson
Yes! Tried in command line. works fine there. Not sure howto customize my
IDE correctly. I use Emacs.
Thanks,
Oleg
On Fri, Apr 4, 2008 at 2:36 PM, Kent Johnson wrote:
> Oleg Oltar wrote:
>
> > Hi!
> > I am trying to use unittest in python first time. But have a strange
> > traceback each time I run my sample tests.
> >
>
> How are you running the test? My guess is that you are running it in an
> IDE or something that shows the normal system exit exception.
>
> Calling sys.exit() raises the SystemExit exception with a result code.
> Normally this is not shown by the runner.
>
> In Python False == 0 so your program is exiting normally with a code of 0
> (no error). It is probably the program runner that is showing the traceback.
>
> Try running the program from the command line.
>
> Kent
>
>
> Can you please explain why I have it. No info about it in the doc. e.g.
> > the code is
> >
> > import unittest
> > import squaren
> >
> > class TestCases(unittest.TestCase):
> > def setUp(self):
> > pass
> >
> > def testsmall(self):
> > self.assertEqual(True, True)
> >
> >
> >
> > if __name__ == '__main__':
> > unittest.main()
> >
> > And the traceback is
> > ----------------------------------------------------------------------
> > Ran 1 test in 0.000s
> >
> > OK
> > Traceback (most recent call last):
> > File "/tmp/py359hJx", line 14, in
> > unittest.main()
> > File "/opt/local/lib/python2.5/unittest.py", line 768, in __init__
> > self.runTests()
> > File "/opt/local/lib/python2.5/unittest.py", line 806, in runTests
> > sys.exit(not result.wasSuccessful())
> > SystemExit: False
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/794acccb/attachment.htm
From rdm at rcblue.com Fri Apr 4 16:12:11 2008
From: rdm at rcblue.com (Dick Moores)
Date: Fri, 04 Apr 2008 07:12:11 -0700
Subject: [Tutor] Don't miss "Python-by-example - new online guide to Python
Standard Library"
Message-ID: <20080404141243.55FCF1E400F@bag.python.org>
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/8e49a5e0/attachment.htm
From brnstrmrs at gmail.com Fri Apr 4 17:15:22 2008
From: brnstrmrs at gmail.com (Brain Stormer)
Date: Fri, 4 Apr 2008 11:15:22 -0400
Subject: [Tutor] Interactive physics simulation over web
Message-ID: <24bc7f6c0804040815s57b3d9ferdc1ff7774db1e178@mail.gmail.com>
I am working on a physics simulation and would like to publish it on the
web. The simulation requires input fields, mouse action (picking points in
a display pane) and movie like feature with play, pause, skip forward and
skip backward. I was wondering if this can be done using Python and a
Python web tool kit like Django. I can see that this can be done using
Java/Java Script but don't feel like re-familiarizing myself to Java. I
looked into the Python web programming
pagebut it didn't answer
my questions. My goal is keep this simulation
completely written in Python.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/5afd8865/attachment.htm
From pylinuxian at gmail.com Fri Apr 4 17:36:34 2008
From: pylinuxian at gmail.com (linuxian iandsd)
Date: Fri, 4 Apr 2008 15:36:34 +0000
Subject: [Tutor] Don't miss "Python-by-example - new online guide to
Python Standard Library"
In-Reply-To: <20080404141243.55FCF1E400F@bag.python.org>
References: <20080404141243.55FCF1E400F@bag.python.org>
Message-ID:
well, good to see something like this comming ... i used to browse for hours
to find nothing but long long documentation & not a single real life
example... but i guess its because i m used to the old 'howto' way of
ducumentation ...
On Fri, Apr 4, 2008 at 2:12 PM, Dick Moores wrote:
> A new one-man project, just getting started.
> < http://www.lightbird.net/py-by-example/>
>
> This guide aims to show examples of use of all Python Library Reference
> functions, methods and classes. At this point, only the more widely used
> modules were added and only functions use examples are given. Python version
> 2.5 was used for examples unless noted otherwise. Example of output of a
> function is shown in the form of function_call(args) # [result]:
>
> math.sqrt(9) # 3.0
>
>
> See the thread in the python-list archive:
>
> Dick Moores
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/cf52bf01/attachment.htm
From adam.jtm30 at gmail.com Fri Apr 4 17:42:33 2008
From: adam.jtm30 at gmail.com (Adam Bark)
Date: Fri, 4 Apr 2008 16:42:33 +0100
Subject: [Tutor] Interactive physics simulation over web
In-Reply-To: <24bc7f6c0804040815s57b3d9ferdc1ff7774db1e178@mail.gmail.com>
References: <24bc7f6c0804040815s57b3d9ferdc1ff7774db1e178@mail.gmail.com>
Message-ID:
On 04/04/2008, Brain Stormer wrote:
>
> I am working on a physics simulation and would like to publish it on the
> web. The simulation requires input fields, mouse action (picking points in
> a display pane) and movie like feature with play, pause, skip forward and
> skip backward. I was wondering if this can be done using Python and a
> Python web tool kit like Django. I can see that this can be done using
> Java/Java Script but don't feel like re-familiarizing myself to Java. I
> looked into the Python web programming pagebut it didn't answer my questions. My goal is keep this simulation
> completely written in Python.
I think you can use Jython in a Java applet, that might be what you're
looking for.
HTH,
Adam.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/090300d6/attachment-0001.htm
From mail at timgolden.me.uk Fri Apr 4 17:48:11 2008
From: mail at timgolden.me.uk (Tim Golden)
Date: Fri, 04 Apr 2008 16:48:11 +0100
Subject: [Tutor] Don't miss "Python-by-example - new online guide
to Python Standard Library"
In-Reply-To:
References: <20080404141243.55FCF1E400F@bag.python.org>
Message-ID: <47F64DBB.6060404@timgolden.me.uk>
linuxian iandsd wrote:
> well, good to see something like this comming ... i used to browse for hours
> to find nothing but long long documentation & not a single real life
> example... but i guess its because i m used to the old 'howto' way of
> ducumentation ...
It's one of those things; people learn in different ways. Some people
prefer dry reference guides; others like the cookbook approach (I do
myself). Still others want a complete worked example. And so on.
For me, documentation in its many forms is a *vital* part of any
software project, especially Open Source stuff. The more people
who put together coherent examples, articles, hints, tips etc.,
the better for the rest of the community.
TJG
From kent37 at tds.net Fri Apr 4 17:53:46 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 04 Apr 2008 11:53:46 -0400
Subject: [Tutor] Interactive physics simulation over web
In-Reply-To:
References: <24bc7f6c0804040815s57b3d9ferdc1ff7774db1e178@mail.gmail.com>
Message-ID: <47F64F0A.8030103@tds.net>
Adam Bark wrote:
> I think you can use Jython in a Java applet, that might be what you're
> looking for.
Yes, but it does increase the size of the download considerably since
jython.jar is needed by the browser.
Kent
From kent37 at tds.net Fri Apr 4 17:55:06 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 04 Apr 2008 11:55:06 -0400
Subject: [Tutor] Interactive physics simulation over web
In-Reply-To: <24bc7f6c0804040815s57b3d9ferdc1ff7774db1e178@mail.gmail.com>
References: <24bc7f6c0804040815s57b3d9ferdc1ff7774db1e178@mail.gmail.com>
Message-ID: <47F64F5A.5030900@tds.net>
Brain Stormer wrote:
> I am working on a physics simulation and would like to publish it on the
> web. The simulation requires input fields, mouse action (picking points
> in a display pane) and movie like feature with play, pause, skip forward
> and skip backward. I was wondering if this can be done using Python and
> a Python web tool kit like Django. I can see that this can be done
> using Java/Java Script but don't feel like re-familiarizing myself to
> Java. I looked into the Python web programming page
> but it didn't answer my
> questions. My goal is keep this simulation completely written in Python.
You can use Python and Django for the server-side of this but for the
client side you probably want to look at JavaScript and / or Flash.
Kent
From midnightjulia at gmail.com Fri Apr 4 19:01:07 2008
From: midnightjulia at gmail.com (Julia)
Date: Fri, 4 Apr 2008 19:01:07 +0200
Subject: [Tutor] Don't miss "Python-by-example - new online guide to
Message-ID:
>
> Message: 4
> Date: Fri, 04 Apr 2008 07:12:11 -0700
> From: Dick Moores
> Subject: [Tutor] Don't miss "Python-by-example - new online guide to
> Python Standard Library"
> To: Python Tutor List
> Message-ID: <20080404141243.55FCF1E400F at bag.python.org>
> Content-Type: text/plain; charset="us-ascii"
>
> An HTML attachment was scrubbed...
> URL:
> http://mail.python.org/pipermail/tutor/attachments/20080404/8e49a5e0/attachment-0001.htm
I really appreciate guides that cut to the core directly. Great work Moores
:)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/1e33a77b/attachment.htm
From byogi at yahoo.com Fri Apr 4 19:33:55 2008
From: byogi at yahoo.com (yogi)
Date: Fri, 4 Apr 2008 10:33:55 -0700 (PDT)
Subject: [Tutor] Python Newbie: Lost in Loop
Message-ID: <345864.14330.qm@web43133.mail.sp1.yahoo.com>
Hi all,
I ?m a Python Newbie. Just 48 hrs into Python.
I am trying to parse a file which is tab spaced.
head -5 of the file in question.
1 rs3094315 0 792429
1 rs6672353 0 817376
1 rs4040617 0 819185
1 rs2980300 0 825852
1 rs2905036 0 832343
1 rs4245756 0 839326
1 rs4075116 0 1043552
1 rs9442385 0 1137258
1 rs10907175 0 1170650
1 rs2887286 0 1196054
column[0] increments [1-22].
column [1] has values I?m interested in
columns [2] Its a Zero
column [3] has values which I pass for range boundary.
My Python code
#/bin/python
import sys, csv, re
# This programme finds the SNPs from the range passed from
the select option
## But first for fixed values.
gen = 16
rval0l = 6009890
rval0u = 6009939
rval1l = 0
rval1u = 0
types = (int, str, int, int)
fis = csv.reader(open("divs.map", "rb"), delimiter='\t',
quoting=csv.QUOTE_NONE) # csv splits columns and this file
is tab spaced
# Reading file line by line and using Regex to match the
gene.
for row in fis:
#if re.search("^[1-9]\-^[1-9]\:^[1-9]\-^[1-9]", row
[3]):
if (str(gen) == str(row[0])):
print 'Match for 16 found looking for SNPs
in range between '+ str(rval0l),str(rval0u)+' '
for row[2] in range (rval0l,rval0u):
print row
My Python code is not behaving as I want it to be.
When I pass the range values .
The Code should parse the file.
Match the value of Col3.
look for values in col(3) within the range limit (Which it
does)
print rows Matching the criteria.(which it does not).
It prints rows which are not even the file.
Can somebody point me in the right direction.
Thanks in advance
yogesh
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
From kent37 at tds.net Fri Apr 4 19:55:17 2008
From: kent37 at tds.net (Kent Johnson)
Date: Fri, 04 Apr 2008 13:55:17 -0400
Subject: [Tutor] Python Newbie: Lost in Loop
In-Reply-To: <345864.14330.qm@web43133.mail.sp1.yahoo.com>
References: <345864.14330.qm@web43133.mail.sp1.yahoo.com>
Message-ID: <47F66B85.4080903@tds.net>
yogi wrote:
> Hi all,
> I ?m a Python Newbie. Just 48 hrs into Python.
> I am trying to parse a file which is tab spaced.
You're close...
> My Python code
> #/bin/python
> import sys, csv, re
>
> # This programme finds the SNPs from the range passed from
> the select option
> ## But first for fixed values.
> gen = 16
> rval0l = 6009890
> rval0u = 6009939
> rval1l = 0
> rval1u = 0
> types = (int, str, int, int)
> fis = csv.reader(open("divs.map", "rb"), delimiter='\t',
> quoting=csv.QUOTE_NONE) # csv splits columns and this file
> is tab spaced
> # Reading file line by line and using Regex to match the
> gene.
> for row in fis:
> #if re.search("^[1-9]\-^[1-9]\:^[1-9]\-^[1-9]", row
> [3]):
> if (str(gen) == str(row[0])):
row[0] is already a string so this could be
if str(gen) == row[0]
or
if gen == int(row[0])
> print 'Match for 16 found looking for SNPs
> in range between '+ str(rval0l),str(rval0u)+' '
> for row[2] in range (rval0l,rval0u):
> print row
This is confused. I think you want all the rows where row[3] (not 2) is
between rval0l and rval0u? So just make this another condition:
if rval0l <= int(row[3]) <= rval0u:
print row
Aside to the list:
Did anyone else know that you can assign to a list element as the target
of a for statement?
In [6]: row=range(3)
In [8]: for row[2] in range(5):
print row
...:
...:
[0, 1, 0]
[0, 1, 1]
[0, 1, 2]
[0, 1, 3]
[0, 1, 4]
Color me surprised.
Kent
From cappy2112 at gmail.com Fri Apr 4 20:26:43 2008
From: cappy2112 at gmail.com (Tony Cappellini)
Date: Fri, 4 Apr 2008 11:26:43 -0700
Subject: [Tutor] Don't miss "Python-by-example - new online guide to
Message-ID: <8249c4ac0804041126n7b56a387pa5373ddf435bac08@mail.gmail.com>
Date: Fri, 04 Apr 2008 07:12:11 -0700
From: Dick Moores
Subject: [Tutor] Don't miss "Python-by-example - new online guide to
Python Standard Library"
To: Python Tutor List
Message-ID: <20080404141243.55FCF1E400F at bag.python.org>
Dick- there was no url with your message.
Also See Python Module Of The Week, by Doug Hellman
http://www.doughellmann.com/projects/PyMOTW/
Doug also has regular columns in Python Magazine-
http://pymag.phparch.com/
a great publication targeted mostly for beginner-intermediate level
Pythonistas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/ae4db887/attachment.htm
From alan.gauld at btinternet.com Fri Apr 4 20:27:43 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Fri, 4 Apr 2008 19:27:43 +0100
Subject: [Tutor] Python Newbie: Lost in Loop
References: <345864.14330.qm@web43133.mail.sp1.yahoo.com>
<47F66B85.4080903@tds.net>
Message-ID:
"Kent Johnson" wrote
> Aside to the list:
> Did anyone else know that you can assign to a list element
> as the target of a for statement?
Nope, and in fact I was just trying it out at the >>> prompt
when your message came in!
On a general point for the OP, I doubt if you need the
csv module for this. You could generate the required data
list using a simple string split() and a single list
comprehension:
fis = [line.split() for line in infile]
Which might simplify things slightly.
Also it might help processing to sort the list based
on the range value. But it depends on what other
extractions/processing need to be done.
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From eric at ericwalstad.com Fri Apr 4 20:42:51 2008
From: eric at ericwalstad.com (Eric Walstad)
Date: Fri, 04 Apr 2008 11:42:51 -0700
Subject: [Tutor] Python Newbie: Lost in Loop
In-Reply-To: <345864.14330.qm@web43133.mail.sp1.yahoo.com>
References: <345864.14330.qm@web43133.mail.sp1.yahoo.com>
Message-ID: <47F676AB.3040501@ericwalstad.com>
Hi Yogi, welcome to Python!
yogi wrote:
...
> if (str(gen) == str(row[0])):
> print 'Match for 16 found
Is the conversion to string really necessary? Even if it is, do it once
for gen, when you define it:
gen = '16'
so you don't have to convert on every iteration of the loop. I think
you want gen to be a integer, though, because you later compare it to
other integers in your range().
...
> for row[2] in range (rval0l,rval0u):
> print row
I don't think this bit is doing what you think it is. For each
iteration you are assigning a value to the third element in the row list:
row[2] = 6009890
row[2] = 6009891
...
row[2] = 6009938
etc.
I don't think you want to loop over the range but instead want to check
to see if row[2] is between rval0l and rval0u. You can do that by using
if x in some_list
which will return true if x is a member of the list. range() will give
you the list of values to check against (but only create that list once
unless it changes on each row you are processing and in your code
example, it's not changing). Remember, it's easy and enlightening to
test code on the Python command line:
>>> rval0l = 6009890
>>> rval0u = 6009939
>>> range(rval0l,rval0u)
[6009890, 6009891, 6009892, 6009893, 6009894, 6009895, 6009896, 6009897,
6009898, 6009899, 6009900, 6009901, 6009902, 6009903, 6009904, 6009905,
6009906, 6009907, 6009908, 6009909, 6009910, 6009911, 6009912, 6009913,
6009914, 6009915, 6009916, 6009917, 6009918, 6009919, 6009920, 6009921,
6009922, 6009923, 6009924, 6009925, 6009926, 6009927, 6009928, 6009929,
6009930, 6009931, 6009932, 6009933, 6009934, 6009935, 6009936, 6009937,
6009938]
>>> my_range = range(rval0l,rval0u)
>>> 6009893 in my_range
True
>>> 5 in my_range
False
gen = 16
idx_snp = 2
my_range = range(rval0l,rval0u)
for row in file:
snp = int(row[idx_snp])
if snp == gen:
print 'Found %s' % gen
if snp in my_range:
print "Found match:", row
Eric.
PS, if your input file is as simple as your example, the csv module
isn't getting you much benefit/complexity:
for row in open("divs.map"):
fields = row.split('\t')
print fields
From jeff at drinktomi.com Fri Apr 4 23:04:03 2008
From: jeff at drinktomi.com (Jeff Younker)
Date: Fri, 4 Apr 2008 14:04:03 -0700
Subject: [Tutor] Which Python Script Editor of Choice?
In-Reply-To: <82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
References: <1128c3c40804030832q77b2405fkba6472552194dfaa@mail.gmail.com>
<82b4f5810804031015y6446fbbfgee3ee5b5c88d9c78@mail.gmail.com>
Message-ID: <67C25E78-E138-401D-B1BB-7E1CB471D997@drinktomi.com>
Jeffrey Dates wrote:
> So as I'm starting to get into writing some scripts, I'm looking for
> recommendations for a nifty script editor. Ideally a freeware/
> shareware solution until I can justify a purchase of something more
> beefy.
>
> Currently I'm using PSPad, however it's pretty dumb and doesn't
> recognize Python context. Which, I suppose is fine, but would be
> nice if there was one. Especially since I'm learning.
I use Eclipse+PyDev plugin+commercial ($30) PyDev extensions (which
runs for free, but nags every hour or so.) I has a feature set that
no other
python IDE has at this point. (Let me qualify that: I haven't looked
at the Iron
Python tools on windows, and they might be better, but I don't do much
in
the windows world so I haven't looked at it yet.)
- Jeff Younker - jeff at drinktomi.com -
From rdm at rcblue.com Sat Apr 5 00:06:20 2008
From: rdm at rcblue.com (Dick Moores)
Date: Fri, 04 Apr 2008 15:06:20 -0700
Subject: [Tutor] Don't miss "Python-by-example - new online guide to
In-Reply-To: <8249c4ac0804041126n7b56a387pa5373ddf435bac08@mail.gmail.co
m>
References: <8249c4ac0804041126n7b56a387pa5373ddf435bac08@mail.gmail.com>
Message-ID: <20080404220630.A86581E4012@bag.python.org>
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20080404/573a1e3e/attachment.htm
From katcipis at inf.ufsc.br Sat Apr 5 03:26:26 2008
From: katcipis at inf.ufsc.br (Tiago Katcipis)
Date: Fri, 04 Apr 2008 22:26:26 -0300
Subject: [Tutor] Question about global variables on modules
Message-ID: <47F6D542.5010001@inf.ufsc.br>
I know its not such a pretty thing to have global variables but its only
for an exercise my teacher told to do. Its a function to calculate the
results of a matrix using jacob. I want to inside the module (inside a
function on the module )assign a value to a global variable, but the
only way i found to do this inside the own module function is importing
the module inside himself. Is there another way of doing this? its kind
odd to import the module to himself, i think :-)
here goes the code
<============>
import lineares_jacob
*ERRO_FINAL = 0.0*
def obter_respostas(matriz, incognitas, erro_max):
erro = erro_max * 10
n = len(matriz)
while(erro >= erro_max):
novas_incognitas = []
y_um = (2.0 + (1.0 * incognitas[1]) - (1.0 * incognitas[4999])) / 3.0
novas_incognitas.append(y_um)
for i in range(1 , (n - 1)):
yi = ( (2.0 * i) + incognitas[i - 1] + incognitas[i + 1] ) / (2.0 + i)
novas_incognitas.append(yi)
y_cinc_mil = (10000.0 - incognitas[0] + incognitas[4998]) / 5002.0
novas_incognitas.append(y_cinc_mil)
maior = novas_incognitas[0] - incognitas[0]
for i in range(1, 5000):
dif = novas_incognitas[i] - incognitas[i]
if(dif > maior):
maior = dif
erro = maior
incognitas = novas_incognitas
*lineares_jacob.ERRO_FINAL = erro*
return incognitas
From byogi at yahoo.com Sat Apr 5 04:24:14 2008
From: byogi at yahoo.com (yogi)
Date: Fri, 4 Apr 2008 19:24:14 -0700 (PDT)
Subject: [Tutor] Python Newbie: Lost in Loop
In-Reply-To: <47F66B85.4080903@tds.net>
Message-ID: <729391.50820.qm@web43132.mail.sp1.yahoo.com>
Hi all ,
Thanks for the input.
I must add Kent's solution was the fastest. The actual file
to parse is 12MB.
Though Eric's solution was more readable ( atleast for me).
Now that I have the logic and code right I have to work on
the real problem.
Thanks in advance,
yogesh
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
From sierra_mtnview at sbcglobal.net Sat Apr 5 05:37:55 2008
From: sierra_mtnview at sbcglobal.net (Wayne Watson)
Date: Fri, 04 Apr 2008 20:37:55 -0700
Subject: [Tutor] Diff for Python
Message-ID: <47F6F413.3070302@sbcglobal.net>
Is there a Linux diff-like command for Python code? I'd like to see the
difference between two py files.
--
Wayne Watson (Watson Adventures, Prop., Nevada City, CA)
(121.015 Deg. W, 39.262 Deg. N) GMT-8 hr std. time)
Obz Site: 39? 15' 7" N, 121? 2' 32" W, 2700 feet
"Philosophy is questions that may never be
answered. Religion is answers that may never
be questioned" -- Anon
Web Page:
From tonytraductor at linguasos.org Sat Apr 5 05:58:51 2008
From: tonytraductor at linguasos.org (Anthony Baldwin)
Date: Fri, 04 Apr 2008 23:58:51 -0400
Subject: [Tutor] Question about global variables on modules
In-Reply-To: <47F6D542.5010001@inf.ufsc.br>
References: <47F6D542.5010001@inf.ufsc.br>
Message-ID: <47F6F8FB.6080500@linguasos.org>
Tiago Katcipis wrote:
> I know its not such a pretty thing to have global variables but its only
> for an exercise my teacher told to do. Its a function to calculate the
> results of a matrix using jacob. I want to inside the module (inside a
> function on the module )assign a value to a global variable, but the
> only way i found to do this inside the own module function is importing
> the module inside himself. Is there another way of doing this? its kind
> odd to import the module to himself, i think :-)
>
> here goes the code
>
Oi, Tiago
N?o sei muito bem como funciona em Python,
sendo que j? estou come?ando a aprender-lo, mais,
deve ter algo como o "uplevel" em Tcl, n?o?
Tcl's uplevel sets a vari?vel pelo namespace global.
Ou talvez algo como
set ::var value (esse funciona em tcl
pra set a vari?vel globalmente mas dentro de um proc)?
/tony
--
Anthony Baldwin
http://www.BaldwinLinguas.com
Translation & Interpreting
http://www.TransProCalc.org
Free translation project mgmt software
http://www.LinguasOS.org
Linux for Translators
From byogi at yahoo.com Sat Apr 5 07:05:05 2008
From: byogi at yahoo.com (yogi)
Date: Fri, 4 Apr 2008 22:05:05 -0700 (PDT)
Subject: [Tutor] Code optmisation
Message-ID: <304770.91464.qm@web43136.mail.sp1.yahoo.com>
Hi ,
Here is my first usable Python code.
The code works.
Here is what I'm trying to do.
I have two huge text files. After some processing, One is 12M (file A) and the other 1M (file B) .
The files have columns which are of interest to me.
I 'm trying to match entries of column [0] on file A and B
If it is true proceed to find entries (Rows in file A) in range provided by columns [1] [2] and [3] [4] in file B.
Column [1] and [3] define the lower bounds of the range
Column [3] and [4] define the upper bounds of the range
I also have put a variation of value so that I can lookup +/- var.
#/bin/python
import sys, os, csv, re
x = 0 #Define Zero for now
var = 1000000 #Taking the variation
# This programme finds the SNPs from the range passed
# csv splits columns and this file is tab spaced
fis = csv.reader(open("divs.map", "rb"), delimiter='\t', quoting=csv.QUOTE_NONE)
for row in fis:
# csv splits columns and this file is "," spaced
gvalues = csv.reader(open("genvalues", "rb"), delimiter=',', quoting=csv.QUOTE_NONE)
for gvalue in gvalues:
# To see Columns (chr) Match
if row[0] == gvalue[0]:
# If Column 3 (range) is Zero print row
if int(gvalue[3]) == x:
a = int(gvalue[1]) - var
b = int(gvalue[2]) + var + 1
if int(a <= int(row[3]) <= b):
print row
# If Column 3 (range) is not zero find matches and print row
else:
a = int(gvalue[1]) - var
b = int(gvalue[2]) + var + 1
if int(a <= int(row[3]) <= b):
print row
c = int(gvalue[3]) - var
d = int(gvalue[4]) + var + 1
if int(c <= int(row[3]) <= d):
print row
-----------------------------------------------------
Question1 : Is there a better way ?
Question2 : For now I'm using shells time call for calculating time required. Does Python provide a more fine grained check.
Question 2: If I have convert this code into a function.
Should I ?
def parse():
...
...
...
...
parse ()
____________________________________________________________________________________
You rock. That's why Blockbuster's offering you one month of Blockbuster Total Access, No Cost.
http://tc.deals.yahoo.com/tc/blockbuster/text5.com
From carroll at tjc.com Sat Apr 5 07:59:42 2008
From: carroll at tjc.com (Terry Carroll)
Date: Fri, 4 Apr 2008 22:59:42 -0700 (PDT)
Subject: [Tutor] Diff for Python
In-Reply-To: <47F6F413.3070302@sbcglobal.net>
Message-ID:
On Fri, 4 Apr 2008, Wayne Watson wrote:
> Is there a Linux diff-like command for Python code? I'd like to see the
> difference between two py files.
You could just use diff.
Python itself also has difflib:
http://python.org/doc/2.5/lib/module-difflib.html
From alan.gauld at btinternet.com Sat Apr 5 09:17:18 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 5 Apr 2008 08:17:18 +0100
Subject: [Tutor] Question about global variables on modules
References: <47F6D542.5010001@inf.ufsc.br>
Message-ID:
"Tiago Katcipis" wrote
> results of a matrix using jacob. I want to inside the module (inside
> a
> function on the module )assign a value to a global variable, but the
> only way i found to do this inside the own module function is
> importing
> the module inside himself. Is there another way of doing this?
Look at the 'global' keyword.
Explained further in the 'What's in a Name' topic of my tutorial.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From alan.gauld at btinternet.com Sat Apr 5 09:44:00 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 5 Apr 2008 08:44:00 +0100
Subject: [Tutor] Code optmisation
References: <304770.91464.qm@web43136.mail.sp1.yahoo.com>
Message-ID:
"yogi" wrote
> #/bin/python
> import sys, os, csv, re
> x = 0 #Define Zero for now
> var = 1000000 #Taking the variation
> # This programme finds the SNPs from the range passed
> # csv splits columns and this file is tab spaced
> fis = csv.reader(open("divs.map", "rb"), delimiter='\t',
> quoting=csv.QUOTE_NONE)
> for row in fis:
> # csv splits columns and this file is "," spaced
> gvalues = csv.reader(open("genvalues", "rb"), delimiter=',',
> quoting=csv.QUOTE_NONE)
Move this outside the loop otherwise you re-read the file
for every line in the other file - slow!
> for gvalue in gvalues:
> # To see Columns (chr) Match
> if row[0] == gvalue[0]:
> # If Column 3 (range) is Zero print row
> if int(gvalue[3]) == x:
> a = int(gvalue[1]) - var
> b = int(gvalue[2]) + var + 1
> if int(a <= int(row[3]) <= b):
> print row
I'd probably use names like 'lo' and 'hi' instead of 'a'
and 'b' but thats a nit pick... but you don't want to convert
the result of the test to an int, the result is a boolean and
you never use the int you create so its just wasted
processing power...
> # If Column 3 (range) is not zero find matches and print row
> else:
> a = int(gvalue[1]) - var
> b = int(gvalue[2]) + var + 1
Repeated code, you could move this above the if test
since its used by both conditions. Easier to maintain if
you change the rules...
> if int(a <= int(row[3]) <= b):
> print row
again you don;t need the int() conversion.
> c = int(gvalue[3]) - var
> d = int(gvalue[4]) + var + 1
> if int(c <= int(row[3]) <=
> d):
and again. You do this so often I'd consider making it a
helper function
def inLimits(min, max, val):
lo = int(min) - var
hi = int(max) + var + 1
return lo <= int(val) <= hi
Your else clause then becomes
else:
if inLmits(gvalue[1],gvalue[2],row[3])
print row
if inLimits(gvalue[3], gvalue[4], row[3]
print row
Which is slightly more readable I think.
> Question1 : Is there a better way ?
There's always a better way.
As a general rule for processing large volumes of data
I tend to go for a SQL database. But thats mainly based
on my experience that if you want to do one lot of queries
you'll eventually want to do more - and SQL is designed
for doing queries on large datasets, Python isn't (although
Python can do SQL...).
> Question2 : For now I'm using shells time call for calculating
> time required. Does Python provide a more fine grained check.
try timeit...
> Question 2: If I have convert this code into a function.
> Should I ?
Only if you have a need to reuse it in a bigger context
or of you want to parameterize it. You could maybe break
it out into smaller helper functions such as the one I
suggested above.
HTH,
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
From srilyk at gmail.com Sat Apr 5 13:09:29 2008
From: srilyk at gmail.com (W W)
Date: Sat, 5 Apr 2008 06:09:29 -0500
Subject: [Tutor] Diff for Python
In-Reply-To:
References: <47F6F413.3070302@sbcglobal.net>
Message-ID: <333efb450804050409k5031dfb4u50e58650a99690bb@mail.gmail.com>
Vim also has a similar command
On Sat, Apr 5, 2008 at 12:59 AM, Terry Carroll wrote:
> On Fri, 4 Apr 2008, Wayne Watson wrote:
>
> > Is there a Linux diff-like command for Python code? I'd like to see the
> > difference between two py files.
>
> You could just use diff.
>
> Python itself also has difflib:
>
> http://python.org/doc/2.5/lib/module-difflib.html
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at 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
From srilyk at gmail.com Sat Apr 5 13:24:16 2008
From: srilyk at gmail.com (W W)
Date: Sat, 5 Apr 2008 06:24:16 -0500
Subject: [Tutor] Code optmisation
In-Reply-To:
References: <304770.91464.qm@web43136.mail.sp1.yahoo.com>
Message-ID: <333efb450804050424u38385086q6c988cd89827e474@mail.gmail.com>
On Sat, Apr 5, 2008 at 2:44 AM, Alan Gauld wrote:
> "yogi" wrote
> > Question 2: If I have convert this code into a function.
> > Should I ?
>
> Only if you have a need to reuse it in a bigger context
> or of you want to parameterize it. You could maybe break
> it out into smaller helper functions such as the one I
> suggested above.
Personally, functions are always fun!
...
And useful. Even if you don't need to play with them later, there's no
loss, because the exercise is in and of itself a good one. Plus, I
think functions tend (though not always) force you to clean up your
code: As Alan has mentioned, there are a few places that you duplicate
code. The exercise of converting to functions will often point out the
fact that you have multiple code.
Have fun!
-Wayne
From eric at ericwalstad.com Sat Apr 5 22:10:07 2008
From: eric at ericwalstad.com (Eric Walstad)
Date: Sat, 5 Apr 2008 13:10:07 -0700
Subject: [Tutor] Diff for Python
In-Reply-To: <47F7D2F9.5000607@sbcglobal.net>
References: <47F6F413.3070302@sbcglobal.net>
<47F7D2F9.5000607@sbcglobal.net>
Message-ID:
And my whoops, I should have sent my first one to the list, too.
I don't run Windows very often. I think 'WinDiff' is what I used
there. Have you tried that?
There's always cygwin, too.
Eric.
On Sat, Apr 5, 2008 at 12:28 PM, Wayne Watson
wrote:
>
> Whoop, I should have specified I'm on Win XP.
>
>
> Eric Walstad wrote:
> Hi Wayne,
>
> On Fri, Apr 4, 2008 at 8:37 PM, Wayne Watson
> wrote:
>
>
> Is there a Linux diff-like command for Python code? I'd like to see the
> difference between two py files.
>
> Why don't you just use diff?
> What OS are you on?
>
> diff -Bu fileone.py filezero.py
From alan.gauld at btinternet.com Sun Apr 6 00:04:42 2008
From: alan.gauld at btinternet.com (Alan Gauld)
Date: Sat, 5 Apr 2008 23:04:42 +0100
Subject: [Tutor] Diff for Python
References: <47F6F413.3070302@sbcglobal.net><47F7D2F9.5000607@sbcglobal.net>
Message-ID:
On Windows you can use FC - File Compare.
Its not as powerful as diff but it will highlight differences.
Help FC
will get you the switch options.
Or just use cygwin - any Unix user on Windows
should get cygwin as a matter of course IMHO! :-)
Alan G.
"Eric Walstad"