Re: [Tutor] Error
> > I began to learn Python and after saving a file gra.py tried to reopen it > and got an error (in the Annex). > > What's the error on re-opening the file ? Also, share what version of Python, OS and editor you are using. FYI, this is a text only list, images of attachments will be filtered. /Ram ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] remove ^ in field
Hi, Sending lab result in HL7. In the following example, I want everything (PATNUMBER~000925015-001) after 000925015 in PID3-1. I want also to remove everything (^^L) after PID5-2. [cid:image002.jpg@01D21E51.F1A0B0B0] Regards, Pierre Perras ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Error
On 04/10/16 18:41, Agnieszka Socha wrote: > I began to learn Python and after saving a file gra.py tried to reopen it > and got an error (in the Annex). This is a text only list so attachments tend to get stripped off. We need a lot more information I'm afraid. What are you using to "reopen" the file? Are you using a text editor or an IDE (like IDLE or eclipse?). Show us the full error text and your code - just paste it into the mail message. It also might help to tell us the Python version and the OS. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] xpath - html entities issue --
On 04/10/16 15:02, bruce wrote: > I did a quick replace ('','&') and it replaced the '' as desired. > So the content only had '&' in it.. You are preonbably better using your parseers escape/unescape facilities. Simple string replacement is notioriously hard to get right. > I can provide a more comprehensive chunk of code, but minimized the post to > get to the heart of the issue. Also, I'd prefer not to use a sep parse lib. Define separate? There are several options in the standard library. All will be more effective than trying to do it by hand. And libxml2dom is not one of them (at least I've never seen it before) so you appear to be breaking your own rules? > > code chunk > > import libxml2dom > q1=libxml2dom You can get the same effect with import libxml2dom as ql > s2= q1.parseString(a.toString().strip(), html=1) > tt=s2.xpath(tpath) > > tt=tt[0].toString().strip() > print "tit "+tt > > - You may have over-simplified a tad, it has become fairly meaningless to us - what are 'a' and 'tpath'? -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] please help me modify this code so that I can utilize raw_input
On 04/10/16 15:04, Richard Koeman wrote: > I would like to modify this code so that instead of me calling the function > with the list as shown [1,2,3,4], the user inputs the list with raw_input. > You don't need to modify your code you just need ton write a function that reads a list from the user. Notice that this can e done by either repeatedly asking the user to input values until they are done or by reading a string containing the values and converting the string to a list of numbers. > """Define a function sum() and a function multiply() that sums and > multiplies (respectively) all the numbers in a list of numbers. For > example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4]) > should return 24.""" I do wish teachers would not ask students to reinvent the wheel. Python already has a perfectly good sum() function. And both problems become trivial if using functools.reduce() > > def sum(mylist = [], *args): > print mylist > sum_of_number = 0 > for i in mylist: > sum_of_number += i > print "The sum of the digits in your number is %s" %(sum_of_number) > def multiply(mylist = [], *args): > product_of_number = 1 > for i in mylist: > product_of_number = product_of_number * i > print "The product of the digits in your number is %s" > %(product_of_number) > > sum([1,2,3,4]) > multiply([1,2,3,4]) Incidentally, notice that the assignment asks you to *return* the results not print them. This is good practice, keep the printing separate from the calculation. You can then print the result, if you wish, with print( sum([]) ) hth -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.amazon.com/author/alan_gauld Follow my photo-blog on Flickr at: http://www.flickr.com/photos/alangauldphotos ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] please help me modify this code so that I can utilize raw_input
I would like to modify this code so that instead of me calling the function with the list as shown [1,2,3,4], the user inputs the list with raw_input. Thanks in advance """Define a function sum() and a function multiply() that sums and multiplies (respectively) all the numbers in a list of numbers. For example, sum([1, 2, 3, 4]) should return 10, and multiply([1, 2, 3, 4]) should return 24.""" def sum(mylist = [], *args): print mylist sum_of_number = 0 for i in mylist: sum_of_number += i print "The sum of the digits in your number is %s" %(sum_of_number) def multiply(mylist = [], *args): product_of_number = 1 for i in mylist: product_of_number = product_of_number * i print "The product of the digits in your number is %s" %(product_of_number) sum([1,2,3,4]) multiply([1,2,3,4]) -- This is a staff email account managed by Simcoe Muskoka Catholic District School Board. This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the sender. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Error
I began to learn Python and after saving a file gra.py tried to reopen it and got an error (in the Annex). Agnieszka Socha ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] xpath - html entities issue --
Hi. Just realized I might have a prob with testing a crawl. I get a page of data via a basic curl. The returned data is html/charset-utf-8. I did a quick replace ('','&') and it replaced the '' as desired. So the content only had '&' in it.. I then did a parseString/xpath to extract what I wanted, and realized I have '' as representative of the '&' in the returned xpath content. My issue, is there a way/method/etc, to only return the actual char, not the html entiy () I can provide a more comprehensive chunk of code, but minimized the post to get to the heart of the issue. Also, I'd prefer not to use a sep parse lib. code chunk import libxml2dom q1=libxml2dom s2= q1.parseString(a.toString().strip(), html=1) tt=s2.xpath(tpath) tt=tt[0].toString().strip() print "tit "+tt - the content of a.toString() (shortened) . . . Organization Development & Change Edition: 10th . . . the xpath results are Organization Development Change Edition: 10th As you can see.. in the results of the xpath (toString()) the & --> I'm wondering if there's a process that can be used within the toString() or do you really have to wrap each xpath/toString with a unescape() kind of process to convert htmlentities to the requisite chars. Thanks ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help
Ok I got it from the solution you provided on your previous mail. Thanks again Thanks Niraj On Tue, Oct 4, 2016 at 12:05 PM, niraj pandeywrote: > Attaching two snapshots here. > > In first snapshot (1.png) I have the label windows without the values and > in second window (2.png) every label have some value. > I want to put these values in front of every label. I have already stored > these values in a variable. > > Thanks > Niraj > > On Mon, Oct 3, 2016 at 10:02 PM, niraj pandey > wrote: > >> Hello Alan , >> >> I am using python 2.7.10 and using RHEL6 >> >> Thanks >> >> >> On Mon, Oct 3, 2016 at 8:53 PM, Alan Gauld via Tutor >> wrote: >> >>> On 03/10/16 10:54, niraj pandey wrote: >>> >>> > I want to add every lebels value here (ie fetch from DB and display in >>> > front of every lebel or I had store every lable value in variable and >>> > display here). >>> >>> You need to tell us which OS, Python version and GUI >>> toolkit you are using. >>> >>> > [image: Inline image 1] >>> >>> This is a text list so images usually get stripped off. >>> If absolutely necessary to send an image use a link to an >>> image gallery somewhere. >>> >>> But at least try to explain what you are trying to show us. >>> >>> > Is there any function which I can use for this (like we have entry.get >>> to >>> > get the value similar any function to put the value) >>> >>> Assuming you are using Tkinter there is an insert() method. >>> To put text at the end of the entry use >>> >>> import tkinter as tk >>> myText = "Hello world" >>> top = tk.Tk() >>> >>> myEntry = tk.Entry(top) >>> myEntry.pack() >>> myEntry.insert(tk.END,mytext) >>> >>> top.mainloop() >>> >>> >>> However a common alternative is to use a StringVar and associate it with >>> the Entry so that changes in the StringVar are automatically >>> shown in the Entry and changes in the Entrey are reflected to the >>> StringVar. Most Tkinter tutorials will show that under StringVar. >>> >>> Of course if you are not using Tkinter most of that will be useless! >>> >>> >>> -- >>> Alan G >>> Author of the Learn to Program web site >>> http://www.alan-g.me.uk/ >>> http://www.amazon.com/author/alan_gauld >>> Follow my photo-blog on Flickr at: >>> http://www.flickr.com/photos/alangauldphotos >>> >>> >>> ___ >>> Tutor maillist - Tutor@python.org >>> To unsubscribe or change subscription options: >>> https://mail.python.org/mailman/listinfo/tutor >>> >> >> >> >> -- >> Success occurs when opportunity and preparation meet >> > > > > -- > Success occurs when opportunity and preparation meet > -- Success occurs when opportunity and preparation meet ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] Need help
Attaching two snapshots here. In first snapshot (1.png) I have the label windows without the values and in second window (2.png) every label have some value. I want to put these values in front of every label. I have already stored these values in a variable. Thanks Niraj On Mon, Oct 3, 2016 at 10:02 PM, niraj pandeywrote: > Hello Alan , > > I am using python 2.7.10 and using RHEL6 > > Thanks > > > On Mon, Oct 3, 2016 at 8:53 PM, Alan Gauld via Tutor > wrote: > >> On 03/10/16 10:54, niraj pandey wrote: >> >> > I want to add every lebels value here (ie fetch from DB and display in >> > front of every lebel or I had store every lable value in variable and >> > display here). >> >> You need to tell us which OS, Python version and GUI >> toolkit you are using. >> >> > [image: Inline image 1] >> >> This is a text list so images usually get stripped off. >> If absolutely necessary to send an image use a link to an >> image gallery somewhere. >> >> But at least try to explain what you are trying to show us. >> >> > Is there any function which I can use for this (like we have entry.get >> to >> > get the value similar any function to put the value) >> >> Assuming you are using Tkinter there is an insert() method. >> To put text at the end of the entry use >> >> import tkinter as tk >> myText = "Hello world" >> top = tk.Tk() >> >> myEntry = tk.Entry(top) >> myEntry.pack() >> myEntry.insert(tk.END,mytext) >> >> top.mainloop() >> >> >> However a common alternative is to use a StringVar and associate it with >> the Entry so that changes in the StringVar are automatically >> shown in the Entry and changes in the Entrey are reflected to the >> StringVar. Most Tkinter tutorials will show that under StringVar. >> >> Of course if you are not using Tkinter most of that will be useless! >> >> >> -- >> Alan G >> Author of the Learn to Program web site >> http://www.alan-g.me.uk/ >> http://www.amazon.com/author/alan_gauld >> Follow my photo-blog on Flickr at: >> http://www.flickr.com/photos/alangauldphotos >> >> >> ___ >> Tutor maillist - Tutor@python.org >> To unsubscribe or change subscription options: >> https://mail.python.org/mailman/listinfo/tutor >> > > > > -- > Success occurs when opportunity and preparation meet > -- Success occurs when opportunity and preparation meet ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor