[Tutor] voluntary work
someboy have some project where can take a very noob and with very little knowledgement of python in the arm where i can work voluntary of course ? the thing is i want learn i read a bit and do some exercises but i am the kind of ppl that need saw the path that will walk so need a route and a little of guide to keep going , thanks pd: i ask the same question at #python in freenode that somebody recommend me the book http://learnpythonthehardway.org/static/LearnPythonTheHardWay.pdf and i check it it righ now. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work
Thanks , but i still are looking for some small project to get work that let me learn in a more interesting way. i not that kind of person that can start app from zero so is hard for me learn new things without some kind of goal. thanks again. On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld wrote: > > "Edgar Almonte" wrote > >> is i want learn i read a bit and do some exercises but i am the kind >> of ppl that need saw the path that will walk so >> need a route and a little of guide to keep going , > > Have you looked at the python web site? There is a > whole section dedicated to tutorials for people who > have never programmed before. Take a look at a few > and choose the one you like - ie the one that aseems > to make most sense to you.. > > HTH, > > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work :p:
Thanks all for the answer, python challenge is cool but i think need more python and programing level that i current have, ( i ended looking for the answer at google ) i will continue reading "Learn Python the Hard Way" 2011/4/25 Thomas C. Hicks : > On Mon, 25 Apr 2011 15:09:02 -0400 > Rafael Durán Castañeda wrote: > >> I recommend you visit >> www.pythonchallenge.com<http://www.pythonchallenge.com> >> >> On 25/04/11 20:42, Wolf Halton wrote: >> "Learn Python the Hard Way" is pretty cool. I am always looking for >> books that lay it out well. Thanks for mentioning it, and good luck >> with your studies. I find that having a project that is a little >> beyond me helps me get better at coding. >> >> -Wolf >> >> On Mon, Apr 25, 2011 at 1:33 PM, Alan Gauld >> mailto:alan.ga...@btinternet.com>> wrote: >> >> "Edgar Almonte" mailto:samud...@gmail.com>> wrote >> >> >> is i want learn i read a bit and do some exercises but i am the kind >> of ppl that need saw the path that will walk so >> need a route and a little of guide to keep going , >> >> Have you looked at the python web site? There is a >> whole section dedicated to tutorials for people who >> have never programmed before. Take a look at a few >> and choose the one you like - ie the one that aseems >> to make most sense to you.. >> >> HTH, >> >> > > I second the recommendation to try out Python Challenge - outstanding > way to learn (at least for me). Another option is to visit > Sourceforge.net and look for python projects still in development. > Open source pojects seem to always need bug finders and smashers as > well as beta testers and I suspect most any of them would appreciate > free help! > > tom > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] after(), how do I use it?
after(delay_ms, callback=None, *args) [#] Registers an alarm callback that is called after a given time. This method registers a callback function that will be called after a given number of milliseconds. Tkinter only guarantees that the callback will not be called earlier than that; if the system is busy, the actual delay may be much longer. The callback is only called once for each call to this method. To keep calling the callback, you need to reregister the callback inside itself: class App: def __init__(self, master): self.master = master self.poll() # start polling def poll(self): ... do something ... self.master.after(100, self.poll) after_cancel to cancel the callback. On Mon, Apr 25, 2011 at 9:15 PM, Wayne Werner wrote: > On Mon, Apr 25, 2011 at 8:02 PM, michael scott > wrote: >> >> Here is the code in its entirety, it works although I don't see after() >> defined, so I assumed it was a built in function. I can just copy and paste >> parts of this code into my project, so its not imperative that I understand, >> but I prefer to use the weapons I've been given. So I hope that you guys can >> understand it a bit better after I post this. > > That it is indeed. Do you understand classes and subclassing in Python? App > is a subclass of tk.Tk. If you have done any of your own programming in > Tkinter, you should know that Tk is the "main" class in Tkinter. If you do a > Google search for "Tkinter after", the top two results will answer your > question: > http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=tkinter+after > HTH, > Wayne > >> >> import Tkinter as tk >> >> class App(tk.Tk): >> def __init__(self,*args, **kwargs): >> tk.Tk.__init__(self, *args, **kwargs) >> self.label = tk.Label(self, text="", width=20, anchor="w") >> self.label.pack(side="top",fill="both",expand=True) >> self.print_label_slowly("Hello, world!") >> >> def print_label_slowly(self, message): >> '''Print a label one character at a time using the event loop''' >> t = self.label.cget("text") >> t += message[0] >> self.label.config(text=t) >> if len(message) > 1: >> self.after(500, self.print_label_slowly, message[1:]) >> >> app = App() >> app.mainloop() >> >> >> >> What is it about you... that intrigues me so? >> >> >> From: Adam Bark >> To: tutor@python.org >> Sent: Mon, April 25, 2011 8:50:16 PM >> Subject: Re: [Tutor] after(), how do I use it? >> >> On 26/04/11 01:36, michael scott wrote: >> > Hello, I asked for help in another location and it solved my problem, >> > but the only problem is I don't fully understand the after function. Here >> > is >> > part of the code that was given to me. >> > >> > >> > def print_label_slowly(self, message): >> > '''Print a label one character at a time using the event loop''' >> > t = self.label.cget("text") >> > t += message[0] >> > self.label.config(text=t) >> > if len(message) > 1: >> > self.after(500, self.print_label_slowly, message[1:]) >> > >> > I understand it, and the gist of how it works, but the self.after... I >> > can not find any documentation on it (because after is such a common word), >> > so can you guys tell me how it works. Is this a built in function (didn't >> > see it on the built in function list)? Does it always take 3 arguements? Is >> > this a user made function and I'm just overlooking where it was defined at? >> >> The function you have shown there appears to be a class method. self.after >> means you are calling another method of the same function that >> print_label_slowly is a part of. >> Do you have the rest of the code? If you're still confused post it and >> hopefully we can clear it up for you. >> >> HTH, >> Adam. >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] voluntary work :p:
you need solve the problem and so far the solution of the problem is the name of the next url example: .html , you need get the result and change in the url bar On Tue, Apr 26, 2011 at 12:19 AM, bob gailer wrote: > On 4/25/2011 11:59 PM, Wolf Halton wrote: >> >> I didn't get anything out of pythonchallenge. > > Nothing? No web pages? > >> All seems static. > > Now you say All instead of nothing. Did you get more than 1 web page? > >> Do you need flash or something to make the magic happen? > > What are you expecting? What magic? > > Did you see an image of a monitor with 2 to the 38 on it? > > Did you see "Hint: try to change the URL address."? > > Did you try that? > > > -- > Bob Gailer > 919-636-4239 > Chapel Hill NC > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Just started Python
try this : model=raw_input("What kind of car do you drive?") gallons=raw_input("How many gallons have you driven?") number1 = float (gallons) miles=raw_input("How many miles have you driven?") number2 = float (miles) try: number1 = float (gallons) number2 = float (miles) except ValueError: print "some values are wrong type." else: print "Your average number of miles to gallons is", print number1 / number2 On Wed, Apr 27, 2011 at 5:11 PM, Noah Hall wrote: > On Wed, Apr 27, 2011 at 9:17 PM, Johnson Tran wrote: >> Thanks for the reply Alan and Noah, I really appreciate the help. I am >> really trying to understand this although still cannot seem to grasp it all. >> I have modified my program although now it seems to be giving me the wrong >> answer with the correct answer when I input any value. >> >> I have program: >> >> model=raw_input("What kind of car do you drive?") >> gallons=raw_input("How many gallons have you driven?") >> number1 = float (gallons) >> miles=raw_input("How many miles have you driven?") >> number2 = float (miles) >> >> >> try: >> model=float(model) >> except ValueError: >> print "I cannot compute your total miles to gallon with those values." >> else: >> print "Your average number of miles to gallons is", >> print number1 / number2 >> >> Output: >> >> What kind of car do you drive?fire >> How many gallons have you driven?10 >> How many miles have you driven?5 >> I cannot compute your total miles to gallon with those values. > > Again, it's because you're "validating" the wrong variable. model is > _not_ what you want to validate - it needs to be a string! gallons and > miles are what you want to validate. So try moving your try: except: > somewhere else, where it will validate the gallons and miles. > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Just started Python
yes i just forget remove the previous one On Wed, Apr 27, 2011 at 5:39 PM, Steve Willoughby wrote: > On 27-Apr-11 14:35, Edgar Almonte wrote: >> >> try this : >> >> >> >> model=raw_input("What kind of car do you drive?") >> gallons=raw_input("How many gallons have you driven?") >> number1 = float (gallons) >> miles=raw_input("How many miles have you driven?") >> number2 = float (miles) >> >> >> try: >> number1 = float (gallons) >> number2 = float (miles) > > Indentation error aside, you'll never reach that exception because the > previous number1 = float(gallons) would raise one if the input was wrong. > Either move the try..except block to enclose the first one, or wait until > the try...except block to do the typecast. > -- > Steve Willoughby / st...@alchemy.com > "A ship in harbor is safe, but that is not what ships are built for." > PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Making a script part of the terminal
hey ! i can answer that ! birst in the fist line of you script put something like this #!/usr/local/bin/python change the path for where you have python ( try using 'whereis python' ) sencond make the file executable add the +x attribute ( using chmod ) third put the script in some place and and that path to the PATH enviroment variable. good luck On Fri, May 20, 2011 at 1:43 PM, michael scott wrote: > Okay, my title might be undescriptive, let me try to explain it better. I > want to take a script I've written and make it usable by typing its name in > the terminal. Perfect example is the python interpreter. You just type in > the word python to the terminal and then the interpreter runs. I know other > programs can do this as well (like mozilla or nautilus or rhythmbox). So > how do I make my scripts executable from the terminal? > > > What is it about you... that intrigues me so? > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] serial device emulator
Hello list need some advice/help with something, i am doing a program in python that send some command via serial to a device so far so good , the thing is not have the program so i need make another program that emulate the behavior of this serial device ( is quiet simple ) to test my app i read abou that i can use pseudo terminal in linux but not sure how attatch the pseudo terminal /dev/pts5 example to a fake_device.py file or something like that. maybe this question is not so python but i will appreciate some help. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] serial device emulator
thanks chirs but i think i don't follow you , can you elaborate more ? Thanks On Mon, Jul 4, 2011 at 8:49 PM, Chris Fuller wrote: > > You don't need to emulate a serial port (since you're writing the code; you'd > have to emulate the port if it was standalone software), only your serial port > library. Write a class that has the same methods as the serial port library > you're using (you only need the methods you're using or think you might use > later), and fill them in with the appropriate code so it behaves like your > real > device. > > Cheers > > On Monday 04 July 2011, Edgar Almonte wrote: >> Hello list need some advice/help with something, i am doing a program >> in python that send some command via serial to a device so far so good >> , the thing is not have the program so i need make another program >> that emulate the behavior of this serial device ( is quiet simple ) to >> test my app >> i read abou that i can use pseudo terminal in linux but not sure how >> attatch the pseudo terminal /dev/pts5 example to a fake_device.py file >> or something like that. >> >> maybe this question is not so python but i will appreciate some help. >> >> >> Thanks >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] serial device emulator
got it , thanks a lot On Tue, Jul 5, 2011 at 8:18 AM, Adam Bark wrote: > What Chris is getting at is that you'll use some module, eg pyserial, to > interface with the serial port. So if you write a little module that has the > same interface then you can pretend you have a serial port attached device > and then switch over to an actual one without changing anything else in your > code but the import. > > ## myserial.py ## > class Serial: > def __init__(self, port=None): > pass > def open(self): > pass > def close(): > pass > def read(size=1): > return 'a' * size > def write(data): > return len(data) > # > > ## foo.py ## > import myserial as serial > #import serial ## Use this in production > > port = serial.Serial() > port.open() > print port.write("hello, world") > print port.read(3) > > > I hope that makes it clearer to you. > Adam. > P.S. none of that code has been tested > > > On 05/07/11 13:03, Edgar Almonte wrote: >> >> thanks chirs but i think i don't follow you , can you elaborate more ? >> >> Thanks >> >> On Mon, Jul 4, 2011 at 8:49 PM, Chris Fuller >> wrote: >>> >>> You don't need to emulate a serial port (since you're writing the code; >>> you'd >>> have to emulate the port if it was standalone software), only your serial >>> port >>> library. Write a class that has the same methods as the serial port >>> library >>> you're using (you only need the methods you're using or think you might >>> use >>> later), and fill them in with the appropriate code so it behaves like >>> your real >>> device. >>> >>> Cheers >>> >>> On Monday 04 July 2011, Edgar Almonte wrote: >>>> >>>> Hello list need some advice/help with something, i am doing a program >>>> in python that send some command via serial to a device so far so good >>>> , the thing is not have the program so i need make another program >>>> that emulate the behavior of this serial device ( is quiet simple ) to >>>> test my app >>>> i read abou that i can use pseudo terminal in linux but not sure how >>>> attatch the pseudo terminal /dev/pts5 example to a fake_device.py file >>>> or something like that. >>>> >>>> maybe this question is not so python but i will appreciate some help. >>>> >>>> >>>> Thanks >>>> ___ >>>> Tutor maillist - Tutor@python.org >>>> To unsubscribe or change subscription options: >>>> http://mail.python.org/mailman/listinfo/tutor >>> >>> ___ >>> Tutor maillist - Tutor@python.org >>> To unsubscribe or change subscription options: >>> http://mail.python.org/mailman/listinfo/tutor >>> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
[Tutor] compare and arrange file
hello , i have a file this a structure like this X | 0.00| 88115.39| X | 90453.29| 0.00| X | 0.00| 90443.29| X | 88115.39| 0.00| X | 0.00| 88335.39| X | 90453.29| 0.00| X | 88335.39| 0.00| X | 90443.29| 0.00| now i need re-arrange the file in this way: X | 0.00| 88115.39| X | 88115.39| 0.00| X | 0.00| 90453.29| X | 90453.29| 0.00| etc i try this http://pastebin.com/2mvxn5GY but without look maybe somebody can give some hint , i know that this is maybe not a directly python question but if somebody can help me I will appreciate it Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
Thanks for the hints , what i want accomplish is sort the line by the same value in the column 2 and 3 i mean the line with the same value in the 2 get together with the line in the same value in column 3 emile and david thanks again let me check the hint that your give me, i will feedback the code if everything workout or else :D On Mon, Jul 11, 2011 at 7:35 PM, Dave Angel wrote: > On 07/11/2011 06:39 PM, Emile van Sebille wrote: > > On 7/11/2011 3:16 PM Edgar Almonte said... > > hello , i have a file this a structure like this > X | 0.00| 88115.39| > X | 90453.29| 0.00| > X | 0.00| 90443.29| > X | 88115.39| 0.00| > X | 0.00| 88335.39| > X | 90453.29| 0.00| > X | 88335.39| 0.00| > X | 90443.29| 0.00| > > now i need re-arrange the file in this way: > X | 0.00| 88115.39| > X | 88115.39| 0.00| > X | 0.00| 90453.29| > X | 90453.29| 0.00| > > etc > > It's not obvious to me for your sample what you want. For example, the 2nd > value 90453.29 from the re-arranged group doesn't appear in the top > sample. > > If I venture a guess, it seems to me that you want the debits and > corresponding offsetting credits listed in sequence. > > In pseudo-code, that might me done as: > > read lines from file > for each line in lines > set flag to D or C based on values > set sortkey to value+flag > append sortkey and line to decorated list > sort decorated list > for key,line in decorated list > print line > > > HTH, > > Emile > > > > > > i try this > http://pastebin.com/2mvxn5GY > but without look > > I also can't see any pattern in the data to give a clue what kind of > filtering you're trying to do. A more specific spec would be useful. > > I can comment on your pastebin code, however. You should have pasted it in > your message, since it's short. > > def splitline(line, z): > if z == 0: > pass > > fields = line.split('|') > nlist = [] > for field in fields: > nlist.append(field) > > return nlist[z] > > The whole loop with nlist is a waste of energy, as you already got a list > from split(). You could replace the function with > def splitline(line, z): > return line.split('|')[z] > > The if z==0 doesn't do anything either. Perhaps you meant to do some error > checking in case the line doesn't have at least z fields. > > But the real problem in your code is the you posted for loop. The inner > loop takes multiple passes through the orig1 file, but the second time won't > get anything, since the file is already positioned at the end. I'd simply > move the open statement inside the outer loop. > > There may be other problems, but that could get you going. > > DaveA > > > > > > > > -- > > DaveA > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
back again, yes that is the idea: "> If I venture a guess, it seems to me that you want the debits and > corresponding offsetting credits listed in sequence." but not sure if i get you pseudo code , you mean some how flag the line when is D or C ( credit of debit ) and then sort by what ? On Mon, Jul 11, 2011 at 6:39 PM, Emile van Sebille wrote: > On 7/11/2011 3:16 PM Edgar Almonte said... >> >> hello , i have a file this a structure like this >> X | 0.00| 88115.39| >> X | 90453.29| 0.00| >> X | 0.00| 90443.29| >> X | 88115.39| 0.00| >> X | 0.00| 88335.39| >> X | 90453.29| 0.00| >> X | 88335.39| 0.00| >> X | 90443.29| 0.00| >> >> now i need re-arrange the file in this way: >> X | 0.00| 88115.39| >> X | 88115.39| 0.00| >> X | 0.00| 90453.29| >> X | 90453.29| 0.00| >> >> etc > > It's not obvious to me for your sample what you want. For example, the 2nd > value 90453.29 from the re-arranged group doesn't appear in the top > sample. > offsetting credits listed in sequence > > In pseudo-code, that might me done as: > > read lines from file > for each line in lines > set flag to D or C based on values > set sortkey to value+flag > append sortkey and line to decorated list > sort decorated list > for key,line in decorated list > print line > > > HTH, > > Emile > > > >> >> >> i try this >> http://pastebin.com/2mvxn5GY >> but without look >> >> maybe somebody can give some hint , i know that this is maybe not a >> directly python question but if somebody can help me I will appreciate >> it >> >> Thanks >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> http://mail.python.org/mailman/listinfo/tutor >> > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
back again david i do the for because the line is delimited by pipeline so and i need get the field number 2 and 3 of the line if i understand well the split('|')[z] will just split till there ( z value ) so if i do split('|')[2] i will get: X , 0.00 and i just want the number value part of the line i try putting the read of orig1 inside the fist loop but that don't see work because the thing is that for some reason the fist loop is just passing one time ( the first one if you see in my code i put a print line1 in the first loop and a print value in the second one and i get something line "line1---" "value1" "value1" "value1" "value1" "value1" "value1" etc. pd: sorry for my bad english On Mon, Jul 11, 2011 at 7:35 PM, Dave Angel wrote: > On 07/11/2011 06:39 PM, Emile van Sebille wrote: > > On 7/11/2011 3:16 PM Edgar Almonte said... > > hello , i have a file this a structure like this > X | 0.00| 88115.39| > X | 90453.29| 0.00| > X | 0.00| 90443.29| > X | 88115.39| 0.00| > X | 0.00| 88335.39| > X | 90453.29| 0.00| > X | 88335.39| 0.00| > X | 90443.29| 0.00| > > now i need re-arrange the file in this way: > X | 0.00| 88115.39| > X | 88115.39| 0.00| > X | 0.00| 90453.29| > X | 90453.29| 0.00| > > etc > > It's not obvious to me for your sample what you want. For example, the 2nd > value 90453.29 from the re-arranged group doesn't appear in the top > sample. > > If I venture a guess, it seems to me that you want the debits and > corresponding offsetting credits listed in sequence. > > In pseudo-code, that might me done as: > > read lines from file > for each line in lines > set flag to D or C based on values > set sortkey to value+flag > append sortkey and line to decorated list > sort decorated list > for key,line in decorated list > print line > > > HTH, > > Emile > > > > > > i try this > http://pastebin.com/2mvxn5GY > but without look > > I also can't see any pattern in the data to give a clue what kind of > filtering you're trying to do. A more specific spec would be useful. > > I can comment on your pastebin code, however. You should have pasted it in > your message, since it's short. > > def splitline(line, z): > if z == 0: > pass > > fields = line.split('|') > nlist = [] > for field in fields: > nlist.append(field) > > return nlist[z] > > The whole loop with nlist is a waste of energy, as you already got a list > from split(). You could replace the function with > def splitline(line, z): > return line.split('|')[z] > > The if z==0 doesn't do anything either. Perhaps you meant to do some error > checking in case the line doesn't have at least z fields. > > But the real problem in your code is the you posted for loop. The inner > loop takes multiple passes through the orig1 file, but the second time won't > get anything, since the file is already positioned at the end. I'd simply > move the open statement inside the outer loop. > > There may be other problems, but that could get you going. > > DaveA > > > > > > > > -- > > DaveA > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
this is just one time thing and the value don't get repeat On Mon, Jul 11, 2011 at 7:55 PM, Steve Willoughby wrote: > On 11-Jul-11 16:50, Edgar Almonte wrote: >> >> Thanks for the hints , what i want accomplish is sort the line by the >> same value in the column 2 and 3 >> >> i mean the line with the same value in the 2 get together with the >> line in the same value in column 3 > > What if the same value appears more than once? Does it matter which ones > you match up? If so, how do you decide? > > -- > Steve Willoughby / st...@alchemy.com > "A ship in harbor is safe, but that is not what ships are built for." > PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
i not too smart steve , can you show me with code ? On Mon, Jul 11, 2011 at 8:22 PM, Steve Willoughby wrote: > On 11-Jul-11 17:18, Edgar Almonte wrote: >> >> this is just one time thing and the value don't get repeat > > Then you could make a single loop over the input lines, building two > dictionaries as you go: > * one that maps column 2's value to the rest of that line's data > * and one that does this for column 3's value. > > Now run through the column 2 data you saved, print that data row, > then look up the value in the other dictionary and print that after it. > >> >> On Mon, Jul 11, 2011 at 7:55 PM, Steve Willoughby >> wrote: >>> >>> On 11-Jul-11 16:50, Edgar Almonte wrote: >>>> >>>> Thanks for the hints , what i want accomplish is sort the line by the >>>> same value in the column 2 and 3 >>>> >>>> i mean the line with the same value in the 2 get together with the >>>> line in the same value in column 3 >>> >>> What if the same value appears more than once? Does it matter which ones >>> you match up? If so, how do you decide? >>> >>> -- >>> Steve Willoughby / st...@alchemy.com >>> "A ship in harbor is safe, but that is not what ships are built for." >>> PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C >>> ___ >>> Tutor maillist - Tutor@python.org >>> To unsubscribe or change subscription options: >>> http://mail.python.org/mailman/listinfo/tutor >>> > > > -- > Steve Willoughby / st...@alchemy.com > "A ship in harbor is safe, but that is not what ships are built for." > PGP Fingerprint 4615 3CCE 0F29 AE6C 8FF4 CA01 73FE 997A 765D 696C > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
thanks emile i understand exactly what you explain me but i was unable to accomplish it ( too noob in python ) but i solved the problem with this code http://pastebin.com/4A6Jz4wZ i will try do what you suggest me anyway but that will tomorrow , tonight i done and i feel good :D Thanks all for the help On Mon, Jul 11, 2011 at 11:01 PM, Emile van Sebille wrote: > On 7/11/2011 5:02 PM Edgar Almonte said... >> >> back again, >> yes that is the idea: >> "> If I venture a guess, it seems to me that you want the debits and >>> >>> corresponding offsetting credits listed in sequence." >> >> >> but not sure if i get you pseudo code , you mean >> some how flag the line when is D or C ( credit of debit ) >> and then sort by what ? >> > > When you sort a list of tuple pairs, it sort on the first item, so > > set sortkey to value+flag > > means the first tuple in the list of tuples to sort should end up with as > value+flag, where the flag is set based on the non-zero value in your line. > > For example, > > XXXs,Dval,Cval = line.split("|") > > then, assuming a consistent valid file structure, > > if int(Dval): key="D"+Dval > else: key="C"+Cval > > then, append (key,line) to your decorated list for each line, and finally > sort and print the lines from your decorated list. > > Emile > > >>>> hello , i have a file this a structure like this >>>> X | 0.00| 88115.39| >>>> X | 90453.29| 0.00| > > > >>> In pseudo-code, that might me done as: >>> >>> read lines from file >>> for each line in lines >>> set flag to D or C based on values >>> set sortkey to value+flag >>> append sortkey and line to decorated list >>> sort decorated list >>> for key,line in decorated list >>> print line > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
On Tue, Jul 12, 2011 at 5:44 AM, Peter Otten <__pete...@web.de> wrote: > Edgar Almonte wrote: > >> thanks emile i understand exactly what you explain me but i was unable >> to accomplish it ( too noob in python ) but i solved the problem with >> this code >> http://pastebin.com/4A6Jz4wZ >> >> i will try do what you suggest me anyway but that will tomorrow , >> tonight i done and i feel good :D > > When you're done compare it to the one below: > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > import csv > > def sortkey(row): > if float(row[1]): > return row[1], True > else: > return row[2], False > > with open("infile.txt", "rb") as instream: > rows = sorted(csv.reader(instream, delimiter="|"), key=sortkey) > > with open("outfile.txt", "wb") as outstream: > csv.writer(outstream, delimiter="|").writerows(rows) > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > This look aweasome i will try it later , thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
On Tue, Jul 12, 2011 at 7:28 AM, Dave Angel wrote: > On 07/12/2011 12:56 AM, Edgar Almonte wrote: >> >> thanks emile i understand exactly what you explain me but i was unable >> to accomplish it ( too noob in python ) but i solved the problem with >> this code >> http://pastebin.com/4A6Jz4wZ >> > (When you post on this list, your comments should follow the pieces you're > responding to. That's a long-standing convention.) > > As I explained earlier, your nested loops won't work correctly, as you fail > to re-open the orig1 file. Since you still seem to think it'll work, I'll > just hope this assignment is for fun, and not for anything that matters. > > In particular, the first line will be compared to all the others. But if > the third line should have matched the seventh, it won't get written out. > -- > > DaveA > > hmm i still don't get you point , i mean why you say that will fail , i copy/read the file 2 times and compare line by line with the second copy of the file ( check the new code at top i do a read() for full read it not more online reading ). anyway i will do the case that you explain and look the result. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
On Tue, Jul 12, 2011 at 5:44 AM, Peter Otten <__pete...@web.de> wrote: > Edgar Almonte wrote: > >> thanks emile i understand exactly what you explain me but i was unable >> to accomplish it ( too noob in python ) but i solved the problem with >> this code >> http://pastebin.com/4A6Jz4wZ >> >> i will try do what you suggest me anyway but that will tomorrow , >> tonight i done and i feel good :D > > When you're done compare it to the one below: > > > import csv > > def sortkey(row): > if float(row[1]): > return row[1], True > else: > return row[2], False > > with open("infile.txt", "rb") as instream: > rows = sorted(csv.reader(instream, delimiter="|"), key=sortkey) > > with open("outfile.txt", "wb") as outstream: > csv.writer(outstream, delimiter="|").writerows(rows) > > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > That code work flawless , aweasome , can you explain to me the code, i have a idea but if you don't mind can you ? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
On Tue, Jul 12, 2011 at 10:32 PM, Emile van Sebille wrote: > On 7/12/2011 4:01 PM Edgar Almonte said... >> >> On Tue, Jul 12, 2011 at 5:44 AM, Peter Otten<__pete...@web.de> wrote: > > >>> >>> import csv > > imports the comma separated values (csv) file handler utilities module > >>> >>> def sortkey(row): >>> if float(row[1]): >>> return row[1], True >>> else: >>> return row[2], False > > ... sortkey defines a function that accepts a cvs.reader data row, and > returns either row[1] and True or row[2] and False based on which of row[1] > and row[2] has a non-zero value > >>> >>> with open("infile.txt", "rb") as instream: >>> rows = sorted(csv.reader(instream, delimiter="|"), key=sortkey) > > rows becomes the sortkey sorted result of the lines of infile.txt > >>> >>> with open("outfile.txt", "wb") as outstream: >>> csv.writer(outstream, delimiter="|").writerows(rows) > > ... and this writes those results to outfile.txt > > you might also try the shortened: > > from csv import reader,writer > > def sortkey(row): return max(row[1],row[2]),row[1]>row[2] > > writer(open("outfile.txt", "wb"), delimiter="|").writerows( > sorted(reader(open("infile.txt", "rb"), delimiter="|"),key=sortkey)) > > > Emile > > ___ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > fist time i saw the statement "with" , is part of the module csv ? , that make a loop through the file ? is not the sortkey function waiting for a paramenter ( the row ) ? i don't see how is get pass , the "key" is a parameter of sorted function ? , reader is a function of csv module ? if "with..." is a loop that go through the file is the second with inside of that loop ? ( i dont see how the write of the output file catch the line readed Thanks again for the helping of my understand ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] compare and arrange file
On Wed, Jul 13, 2011 at 11:02 AM, Peter Otten <__pete...@web.de> wrote: > Edgar Almonte wrote: > >> fist time i saw the statement "with" , is part of the module csv ? , >> that make a loop through the file ? is not the sortkey function >> waiting for a paramenter ( the row ) ? i don't see how is get pass , >> the "key" is a parameter of sorted function ? , reader is a function >> of csv module ? if "with..." is a loop that go through the file is >> the second with inside of that loop ? ( i dont see how the write of >> the output file catch the line readed > > with open(filename) as fileobj: > do_something_with(fileobj) > > is a shortcut for > > fileobj = open(filename) > do_something_with(fileobj) > fileobj.close() > > But it is not only shorter; it also guarantees that the file will be closed > even if an error occurs while it is being processed. > > In my code the file object is wrapped into a csv.reader. > > for row in csv.reader(fileobj, delimiter="|"): > # do something with row > > walks through the file one row at a time where the row is a list of the > columns. To be able to sort these rows you have to read them all into > memory. You typically do that with > > rows_iter = csv.reader(fileobj, delimiter="|") > rows = list(rows_iter) > > and can then sort the rows with > > rows.sort() > > Because this two-step process is so common there is a builtin sorted() that > converts an iterable (the rows here) into a sorted list. Now consider the > following infile: > > $ cat infile.txt > a | 0.00| 1.11| > b | 0.00| 1.11| > X | 0.00| 88115.39| > X | 90453.29| 0.00| > X | 0.00| 90443.29| > c | 1.11| 0.00| > X | 88115.39| 0.00| > X | 0.00| 88335.39| > X | 90453.29| 0.00| > X | 88335.39| 0.00| > X | 90443.29| 0.00| > d | 1.11| 0.00| > > If we read it and sort it we get the following: > >>>> import csv >>>> with open("infile.txt") as fileobj: > ... rows = sorted(csv.reader(fileobj, delimiter="|")) > ... >>>> from pprint import pprint >>>> pprint(rows) > [['X ', ' 0.00', ' 88115.39', ''], > ['X ', ' 0.00', ' 88335.39', ''], > ['X ', ' 0.00', ' 90443.29', ''], > ['X ', ' 88115.39', ' 0.00', ''], > ['X ', ' 88335.39', ' 0.00', ''], > ['X ', ' 90443.29', ' 0.00', ''], > ['X ', ' 90453.29', ' 0.00', ''], > ['X ', ' 90453.29', ' 0.00', ''], > ['a ', ' 0.00', ' 1.11', ''], > ['b ', ' 0.00', ' 1.11', ''], > ['c ', ' 1.11', ' 0.00', ''], > ['d ', ' 1.11', ' 0.00', '']] > > Can you infer the sort order of the list of lists above? The rows are sorted > by the first item in the list, then rows whose first item compares equal are > sorted by the second and so on. This sort order is not something built into > the sort() method, but rather the objects that are compared. sort() uses the > usual operators like < and == internally. Now what would you do if you > wanted to sort your data by the third column, say? Here the key parameter > comes into play. You can use it to provide a function that takes an item in > the list to be sorted and returns something that is used instead of the > items to compare them to each other: > >>> def extract_third_column(row): > ... return row[2] > ... >>>> rows.sort(key=extract_third_column) >>>> pprint(rows) > [['X ', ' 88115.39', ' 00