problems with opening files due to file's path
Okay, so what I want my program to do it open a file, a music file in specific, and for this we will say it is an .mp3. Well, I am using the system() command from the os class. The problem I am running into is that when I send the path of the file to the system() command, which for those of you who don't know the system command is the equivalent of typing one command into command prompt or terminal depending on your system. But let's say that the file is "C:\Music\01 - Track.mp3" or something like that where the number 0 is next to the backslash. Another example is this "C:\Music\track(single)\Track.mp3" The problem here is that the ")" at the end of the single, is conflicting with the backslash as well. Now here is the exact code I was trying to do and when I run it I get false returned. system("\"C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"") Okay, now as you can see it sends it to the system with quotes "\"" and works if I change the file path and get rid of the "04" and the ")" it works, so that is the problem no doubt. If anyone has a way to do this please let me know, or even another way to open a music file like this. Help? -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17759531.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Gerhard Häring wrote: > > Alexnb wrote: >> Okay, so what I want my program to do it open a file, a music file in >> specific, and for this we will say it is an .mp3. Well, I am using the >> system() command from the os class. [...] >> >> system("\"C:\Documents and Settings\Alex\My Documents\My >> Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"") >> [...] > > Try os.startfile() instead. It should work better. > > -- Gerhard > > -- > http://mail.python.org/mailman/listinfo/python-list > > No, it didn't work, but it gave me some interesting feedback when I ran it in the shell. Heres what it told me: >>> os.startfile("C:\Documents and Settings\Alex\My Documents\My >>> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >>> Yours.wma") Traceback (most recent call last): File "", line 1, in os.startfile("C:\Documents and Settings\Alex\My Documents\My Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm Yours.wma") WindowsError: [Error 2] The system cannot find the file specified: "C:\\Documents and Settings\\Alex\\My Documents\\My Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm Yours.wma" See it made each backslash into two, and the one by the parenthesis and the 0 turned into an x -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17759825.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Hey thanks!, both the raw and the double backslashes worked. You are a gentleman and a scholar. Mike Driscoll wrote: > > On Jun 10, 11:45 am, Alexnb <[EMAIL PROTECTED]> wrote: >> Gerhard Häring wrote: >> >> > Alexnb wrote: >> >> Okay, so what I want my program to do it open a file, a music file in >> >> specific, and for this we will say it is an .mp3. Well, I am using the >> >> system() command from the os class. [...] >> >> >> system("\"C:\Documents and Settings\Alex\My Documents\My >> >> Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"") >> >> [...] >> >> > Try os.startfile() instead. It should work better. >> >> > -- Gerhard >> >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> No, it didn't work, but it gave me some interesting feedback when I ran >> it >> in the shell. Heres what it told me: >> >> >>> os.startfile("C:\Documents and Settings\Alex\My Documents\My >> >>> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >> >>> Yours.wma") >> >> Traceback (most recent call last): >> File "", line 1, in >> os.startfile("C:\Documents and Settings\Alex\My Documents\My >> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >> Yours.wma") >> >> WindowsError: [Error 2] The system cannot find the file specified: >> "C:\\Documents and Settings\\Alex\\My Documents\\My >> Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm >> Yours.wma" >> >> See it made each backslash into two, and the one by the parenthesis and >> the >> 0 turned into an x >> -- >> View this message in >> context:http://www.nabble.com/problems-with-opening-files-due-to-file%27s-pat... >> Sent from the Python - python-list mailing list archive at Nabble.com. > > Yeah. You need to either double all the backslashes or make it a raw > string by adding an "r" to the beginning, like so: > > os.startfile(r'C:\path\to\my\file') > > HTH > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17761126.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Well, now i've hit another problem, this time being that the path will be a variable, and I can't figure out how to make startfile() make it raw with a variable, if I put startfile(r variable), it doesn't work and startfile(rvariable) obviously won't work, do you know how to make that work or better yet, how to take a regular string that is given and make every single "\" into a double "\\"? Mike Driscoll wrote: > > On Jun 10, 11:45 am, Alexnb <[EMAIL PROTECTED]> wrote: >> Gerhard Häring wrote: >> >> > Alexnb wrote: >> >> Okay, so what I want my program to do it open a file, a music file in >> >> specific, and for this we will say it is an .mp3. Well, I am using the >> >> system() command from the os class. [...] >> >> >> system("\"C:\Documents and Settings\Alex\My Documents\My >> >> Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The Sun.wma\"") >> >> [...] >> >> > Try os.startfile() instead. It should work better. >> >> > -- Gerhard >> >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> No, it didn't work, but it gave me some interesting feedback when I ran >> it >> in the shell. Heres what it told me: >> >> >>> os.startfile("C:\Documents and Settings\Alex\My Documents\My >> >>> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >> >>> Yours.wma") >> >> Traceback (most recent call last): >> File "", line 1, in >> os.startfile("C:\Documents and Settings\Alex\My Documents\My >> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >> Yours.wma") >> >> WindowsError: [Error 2] The system cannot find the file specified: >> "C:\\Documents and Settings\\Alex\\My Documents\\My >> Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm >> Yours.wma" >> >> See it made each backslash into two, and the one by the parenthesis and >> the >> 0 turned into an x >> -- >> View this message in >> context:http://www.nabble.com/problems-with-opening-files-due-to-file%27s-pat... >> Sent from the Python - python-list mailing list archive at Nabble.com. > > Yeah. You need to either double all the backslashes or make it a raw > string by adding an "r" to the beginning, like so: > > os.startfile(r'C:\path\to\my\file') > > HTH > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17761338.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
No this time it perhaps gave me the worst of all heres what I entered, and the output >>> startfile(r"%s"%full)***full is the path*** startfile(r"%s"%full) WindowsError: [Error 2] The system cannot find the file specified: '"C:\\Documents and Settings\\Alex\\My Documents\\My Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I\'m Yours (Single)\x01 - I\'m Yours.wma"' Thomas Morton wrote: > > maybe try string substitution... not sure if that's really the BEST way to > do it but it should work > > startfile(r"%s"%variable) > > -- > From: "Alexnb" <[EMAIL PROTECTED]> > Sent: Tuesday, June 10, 2008 7:05 PM > To: > Subject: Re: problems with opening files due to file's path > >> >> Well, now i've hit another problem, this time being that the path will be >> a >> variable, and I can't figure out how to make startfile() make it raw with >> a >> variable, if I put startfile(r variable), it doesn't work and >> startfile(rvariable) obviously won't work, do you know how to make that >> work >> or better yet, how to take a regular string that is given and make every >> single "\" into a double "\\"? >> >> Mike Driscoll wrote: >>> >>> On Jun 10, 11:45 am, Alexnb <[EMAIL PROTECTED]> wrote: >>>> Gerhard Häring wrote: >>>> >>>> > Alexnb wrote: >>>> >> Okay, so what I want my program to do it open a file, a music file >>>> in >>>> >> specific, and for this we will say it is an .mp3. Well, I am using >>>> >> the >>>> >> system() command from the os class. [...] >>>> >>>> >> system("\"C:\Documents and Settings\Alex\My Documents\My >>>> >> Music\Rhapsody\Bryanbros\Weezer\(2001)\04 - Island In The >>>> Sun.wma\"") >>>> >> [...] >>>> >>>> > Try os.startfile() instead. It should work better. >>>> >>>> > -- Gerhard >>>> >>>> > -- >>>> >http://mail.python.org/mailman/listinfo/python-list >>>> >>>> No, it didn't work, but it gave me some interesting feedback when I ran >>>> it >>>> in the shell. Heres what it told me: >>>> >>>> >>> os.startfile("C:\Documents and Settings\Alex\My Documents\My >>>> >>> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >>>> >>> Yours.wma") >>>> >>>> Traceback (most recent call last): >>>> File "", line 1, in >>>> os.startfile("C:\Documents and Settings\Alex\My Documents\My >>>> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >>>> Yours.wma") >>>> >>>> WindowsError: [Error 2] The system cannot find the file specified: >>>> "C:\\Documents and Settings\\Alex\\My Documents\\My >>>> Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm >>>> Yours.wma" >>>> >>>> See it made each backslash into two, and the one by the parenthesis and >>>> the >>>> 0 turned into an x >>>> -- >>>> View this message in >>>> context:http://www.nabble.com/problems-with-opening-files-due-to-file%27s-pat... >>>> Sent from the Python - python-list mailing list archive at Nabble.com. >>> >>> Yeah. You need to either double all the backslashes or make it a raw >>> string by adding an "r" to the beginning, like so: >>> >>> os.startfile(r'C:\path\to\my\file') >>> >>> HTH >>> >>> Mike >>> -- >>> http://mail.python.org/mailman/listinfo/python-list >>> >>> >> >> -- >> View this message in context: >> http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17761338.html >> Sent from the Python - python-list mailing list archive at Nabble.com. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list > > -- > http://mail.python.org/mailman/listinfo/python-list > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17761946.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
That would work, but not for what I want. See the file could be anywhere on the user's system and so the entire path will be unique, and that didn't work with a unique path. What is the subprocess module you are talking about? Mike Driscoll wrote: > > On Jun 10, 1:25 pm, "Thomas Morton" <[EMAIL PROTECTED]> > wrote: >> maybe try string substitution... not sure if that's really the BEST way >> to >> do it but it should work >> >> startfile(r"%s"%variable) > > > I concur. That should work. A slightly more in depth example (assuming > Windows): > > os.startfile(r'C:\Documents and Settings\%s\Desktop\myApp.exe' % > username) > > or > > os.startfile(r'C:\Program Files\%s' % myApp) > > Hopefully this is what you are talking about. If you were referring to > passing in arguments, than you'll want to use the subprocess module > instead. > > >> >> -- >> From: "Alexnb" <[EMAIL PROTECTED]> >> Sent: Tuesday, June 10, 2008 7:05 PM >> To: <[EMAIL PROTECTED]> >> Subject: Re: problems with opening files due to file's path >> >> >> >> > Well, now i've hit another problem, this time being that the path will >> be >> > a >> > variable, and I can't figure out how to make startfile() make it raw >> with >> > a >> > variable, if I put startfile(r variable), it doesn't work and >> > startfile(rvariable) obviously won't work, do you know how to make that >> > work >> > or better yet, how to take a regular string that is given and make >> every >> > single "\" into a double "\\"? >> > > > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17762276.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
I am using GUI, Tkinter to be exact. But regardless of how the path gets there, it needs to opened correctly. The problem I am running into is that the program receives a path of a file, either .wma or .mp3 and is supposed to open it. I run into problems when there is either a ")" or a number next to the backslash "\" in the file path. I am looking for a way to make it work with a variable, I can make it work when I physically type it in, but not with a variable that holds the path. Mike Driscoll wrote: > > On Jun 10, 1:57 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> That would work, but not for what I want. See the file could be anywhere >> on >> the user's system and so the entire path will be unique, and that didn't >> work with a unique path. What is the subprocess module you are talking >> about? >> > > > > > As Carsten pointed out, we don't really know what you're doing. Or at > least, I don't. Why do you even want to do string substitution? How > does the user navigate to the files that the user wants to open? Are > you using a GUI or a command line interface? > > Anyway, Google is your friend. Searching for "python subprocess" gives > you this: > > http://docs.python.org/lib/module-subprocess.html > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17767518.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Okay, I don't understand how it is too vague, but here: >>> path = "C:\Documents and Settings\Alex\My Documents\My >>> Music\Rhapsody\Bryanbros\Jason Mraz\I'm Yours (Single)\01 - I'm >>> Yours.wma" >>> os.startfile(path) Traceback (most recent call last): File "", line 1, in os.startfile(path) WindowsError: [Error 2] The system cannot find the file specified: "C:\\Documents and Settings\\Alex\\My Documents\\My Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm Yours.wma" Here's another way: >>> os.startfile(r"%s"%path) Traceback (most recent call last): File "", line 1, in os.startfile(r"%s"%path) WindowsError: [Error 2] The system cannot find the file specified: "C:\\Documents and Settings\\Alex\\My Documents\\My Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\x01 - I'm Yours.wma" Same output, however if I personally input it like so: >>> os.startfile("C:\\Documents and Settings\\Alex\\My Documents\\My >>> Music\\Rhapsody\\Bryanbros\\Jason Mraz\\I'm Yours (Single)\\01 - I'm >>> Yours.wma") It works out fine because I can make each backslash doubles so it doesn't mess stuff up. So if I could take the path varible and make ever "\" into a "\\" then it would also work. Did I clarify? Grant Edwards wrote: > > On 2008-06-11, Alexnb <[EMAIL PROTECTED]> wrote: > >> I am using GUI, Tkinter to be exact. But regardless of how the >> path gets there, it needs to opened correctly. The problem I >> am running into is that the program receives a path of a file, >> either .wma or .mp3 and is supposed to open it. I run into >> problems when there is either a ")" or a number next to the >> backslash "\" in the file path. I am looking for a way to make >> it work with a variable, I can make it work when I physically >> type it in, but not with a variable that holds the path. > > You're going to have to show us code and example input and > output. Your description of the problem is far too vague for > anybody to help you. > > -- > Grant Edwards grante Yow! With YOU, I can > be > at MYSELF... We don't NEED >visi.comDan Rather... > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17768511.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
I don't think you understand it doesn't matter how the variable gets there, the same code is run regardless, I have no problem with the GUI, but you asked, and so I told you. the code os.startfile( is run if there is a GUI or it is a console app. Carsten Haese-2 wrote: > > Alexnb wrote: >> Okay, I don't understand how it is too vague, but here: >> > > [snip a bunch of irrelevant examples...] >> >> Did I clarify? > > No. Earlier you wrote: > >>> On 2008-06-11, Alexnb <[EMAIL PROTECTED]> wrote: >>>> I am using GUI, Tkinter to be exact. But regardless of how the >>>> path gets there, it needs to opened correctly. > > This implies that the file doesn't get opened correctly if the file name > is entered/chosen in the GUI. Yet, the examples you posted don't contain > any GUI code whatsoever. They merely demonstrate that you don't have a > firm grasp on how backslashes in string literals are treated. > > So, this begs the question, do you actually have any GUI code that is > failing, or are you just worried, given the problems you had with string > literals, that the GUI code you have yet to write will fail in the same > way? > > If this is the case, you should just write the GUI code and try it. It > might just work. Backslashes entered into a GUI text box are not treated > the same as backslashes in a Python string literal. > > If, on the other hand, you do have some GUI code for getting the file > name from the user, and that code is failing, then please, show us THAT > CODE and show us how it's failing. > > -- > Carsten Haese > http://informixdb.sourceforge.net > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17769178.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Okay, so as a response to all of you, I will be using the Entry() widget in Tkinter to get this path. and the repr() function just makes all my backslashes 4 instead of just 1, and it still screwes it up with the numbers and parenthesis is has been since the first post. Oh and I know all about escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough to know that I like python better. Anyway, so far I tried all of your stuff, and it didn't work. infact, it puts backslashes in front of the "'" in some of the words, such as "I'm" goes to "I\'m." So I posted the code I will be using if you want to see the Tkinter code I can post it, but I don't see how it will help. Lie Ryan wrote: > > On Jun 11, 9:14 pm, Carsten Haese <[EMAIL PROTECTED]> wrote: >> Lie wrote: >> > In most GUI toolkits (including Tkinter) and raw_input() function, >> > when you input a string (using the textbox, a.k.a Entry widget) it >> > would automatically be escaped for you, so when you input 'path\path >> > \file.txt', the GUI toolkit would convert it into 'path\\path\ >> > \file.txt'. >> >> That's incorrect. If you enter text into a text box or in raw_input(), >> *no* conversion of backslashes is happening. A backslash entered in >> raw_input is just a backslash. A backslash entered in a textbox is just >> a backslash. A backslash read from a file is just a backslash. > > I know, but I thought it'd be easier for him to understand it like > that and discover the real 'how-it-works' later. My guilt is that I > forget to put a "this is not how it actually works behind the scene, > but you can think of it like this at least for now since this model is > easier to grasp (although misleading)". > >> A "conversion" happens when you print the repr() of a string that was >> obtained from raw_input or from a text box, because repr() tries to show >> the string literal that would result in the contents, and in a string >> literal, a backslash is not (always) a backslash, so repr() escapes the >> backslashes: >> >> py> text = raw_input("Enter some text: ") >> Enter some text: This is a backslash: \ >> py> print text >> This is a backslash: \ >> py> print repr(text) >> 'This is a backslash: \\' >> >> As you can see, I entered a single backslash, and the string ends up >> containing a single backslash. Only when I ask Python for the repr() of >> the string does the backslash get doubled up. >> >> -- >> Carsten Haesehttp://informixdb.sourceforge.net > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17782866.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
I posted the underlying code, but I haven't made the GUI code because if I can't get the underlying code right it doesn't matter, well in my eyes it doesn't but I am probably wrong. But it will look somehting like this: e = Entry() #when user hits submit) path = e.get() os.startfile(path) this is very simplified, but that is the idea, and basically exactly what will happen, just if the path has some of those characters that conflict with the \. Carsten Haese-2 wrote: > > Alexnb wrote: >> Okay, so as a response to all of you, I will be using the Entry() widget >> in >> Tkinter to get this path. and the repr() function just makes all my >> backslashes 4 instead of just 1, and it still screwes it up with the >> numbers >> and parenthesis is has been since the first post. Oh and I know all about >> escape characters, (\n,\b,\a,etc.) I can program C, not a lot, but enough >> to >> know that I like python better. Anyway, so far I tried all of your stuff, >> and it didn't work. infact, it puts backslashes in front of the "'" in >> some >> of the words, such as "I'm" goes to "I\'m." So I posted the code I will >> be >> using if you want to see the Tkinter code I can post it, but I don't see >> how >> it will help. > > Your reluctance to post your code puzzles me. Several people have asked > you several times to post your code. We're not doing this to waste your > time. In fact, your reluctance to post your code wastes your time and > our time by making us guess. > > Seeing your code should enable us to see exactly what the problem is. > Your vague descriptions of what's going on are not useful because they > are filtered through your inaccurate understanding of what's going on. I > mean no offense by this, but if your understanding were accurate, you > wouldn't be here asking for help. > > So, if you want us to help you, please humor us and post the actual code > that gets the filename from the user and attempts to open the file. Also > tell us what input you're entering and the output the code produces. > > -- > Carsten Haese > http://informixdb.sourceforge.net > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17786320.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
I don't get why yall are being so rude about this. My problem is this; the path, as a variable conflicts with other characters in the path, creating escape characters I don't want, so I need a way to send the string to the os.startfile() in raw, or, with all the backslashes doubled. Thats it, I'll write some code of what it should work like, because I probably should have done that; but you don't have to act like I am retarded... that solves nothing. Grant Edwards wrote: > > On 2008-06-11, Alexnb <[EMAIL PROTECTED]> wrote: > >> Okay, so as a response to all of you, I will be using the Entry() widget >> in >> Tkinter to get this path. > > OK. > >> and the repr() function just makes all my backslashes 4 >> instead of just 1, and it still screwes it up with the numbers >> and parenthesis is has been since the first post. > > I've absolutely no clue why you would be using the repr() > function. > >> Oh and I know all about escape characters, (\n,\b,\a,etc.) > > Apparently not. > >> I can program C, not a lot, but enough to know that I like >> python better. Anyway, so far I tried all of your stuff, and >> it didn't work. > > To what does "it" refer? > >> infact, it puts backslashes in front of the >> "'" in some of the words, such as "I'm" goes to "I\'m." > > Again, "it" doesn't seem to have a concrete referant. > >> So I posted the code I will be using if you want to see the >> Tkinter code I can post it, but I don't see how it will help. > > If you know what would help and what wouldn't, then you must > know enough to fix your problems. So please do so and quit > bothering the newgroup. > > -- > Grant Edwards grante Yow! I want another > at RE-WRITE on my CEASAR >visi.comSALAD!! > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17786386.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
basic code of what I am doing
Okay, so I wrote some code of basically what I will be doing, only with exactly what I need for this part of the program but here you go: [code] from Tkinter import* import os class myApp: def __init__(self, parent): self.parent = parent self.baseContainer = Frame(self.parent) self.baseContainer.pack() self.e = Entry(self.baseContainer) self.e.bind("", self.entryEnter) self.e.pack() self.Button1 = Button(self.baseContainer, command = self.buttonClick) self.Button1.configure(text="Submit") self.Button1.pack() def buttonClick(self): print "Button1 was clicked" path = self.e.get() path = "\"" + path + "\"" print path #os.startfile(path) def entryEnter(self, event): print "Enter was hit in the entry box" self.buttonClick() root = Tk() myapp = myApp(root) root.mainloop() [code] Alexnb wrote: > > I don't get why yall are being so rude about this. My problem is this; the > path, as a variable conflicts with other characters in the path, creating > escape characters I don't want, so I need a way to send the string to the > os.startfile() in raw, or, with all the backslashes doubled. Thats it, > I'll write some code of what it should work like, because I probably > should have done that; but you don't have to act like I am retarded... > that solves nothing. > > > Grant Edwards wrote: >> >> On 2008-06-11, Alexnb <[EMAIL PROTECTED]> wrote: >> >>> Okay, so as a response to all of you, I will be using the Entry() widget >>> in >>> Tkinter to get this path. >> >> OK. >> >>> and the repr() function just makes all my backslashes 4 >>> instead of just 1, and it still screwes it up with the numbers >>> and parenthesis is has been since the first post. >> >> I've absolutely no clue why you would be using the repr() >> function. >> >>> Oh and I know all about escape characters, (\n,\b,\a,etc.) >> >> Apparently not. >> >>> I can program C, not a lot, but enough to know that I like >>> python better. Anyway, so far I tried all of your stuff, and >>> it didn't work. >> >> To what does "it" refer? >> >>> infact, it puts backslashes in front of the >>> "'" in some of the words, such as "I'm" goes to "I\'m." >> >> Again, "it" doesn't seem to have a concrete referant. >> >>> So I posted the code I will be using if you want to see the >>> Tkinter code I can post it, but I don't see how it will help. >> >> If you know what would help and what wouldn't, then you must >> know enough to fix your problems. So please do so and quit >> bothering the newgroup. >> >> -- >> Grant Edwards grante Yow! I want another >> at RE-WRITE on my CEASAR >>visi.comSALAD!! >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17786712.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Well, I don't understand why I don't need to change anything because say I run that code, which goes straight from the entry box to the startfile() function. It doesn't work with some of the paths, that is the whole problem. the problem is when I enter a path with those certain characters next to each other. Everyone seems like there is some huge thing that I am missing... and I don't know what it is, because when I run that code, with that path I was talking about, I get an error, and it shows me that it is because of the \0. Jerry Hill wrote: > > On Wed, Jun 11, 2008 at 4:16 PM, Alexnb <[EMAIL PROTECTED]> wrote: >> >> I posted the underlying code, but I haven't made the GUI code because if >> I >> can't get the underlying code right it doesn't matter, well in my eyes it >> doesn't but I am probably wrong. But it will look somehting like this: > > What you're missing is that all of the problems you're having with > escape characters *only apply to string literals inside your python > source code.* If you're getting the string from the console, you > don't need to escape or change anything. If you're getting the string > from a Tk text box, you don't need to escape or change anything. If > you're getting the string from the filesystem, you don't need to > escape or change anything. > > The only place you have to be careful is when you type out a literal > string inside your .py source code. When you do that, you need to > properly escape backslashes, either by putting them in raw strings, or > by doubling up your backslashes. > > If you haven't already, reread the section of the python tutorial > about string literals: http://docs.python.org/tut/node5.html. > > -- > Jerry > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17787168.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: problems with opening files due to file's path
Haha, okay well sorry that I was being so stupid, but I get it now and I apoligize for causing you all the frustration. But I did get it to work finally. Carsten Haese-2 wrote: > > Alexnb wrote: >> I don't get why yall are being so rude about this. > > We're frustrated with your apparent inability to understand anything > we're saying. > >> My problem is this; the >> path, as a variable conflicts with other characters in the path, creating >> escape characters I don't want, so I need a way to send the string to the >> os.startfile() in raw, or, with all the backslashes doubled. > > No, no, no, no, NO! That is not your problem! You are drawing unfounded > conclusions from the fact that you had to double up backslashes when the > filename came from a string literal. The situation is entirely different > when the filename comes from user input. No doubling up of backslashes > is necessary when the filename comes from user input. TRUST ME! > > For simplicity, start with this code to convince yourself: > > import os > filename = raw_input("Please enter a filename: ") > os.startfile(filename) > > Once you get that to work, replace raw_input with a function that gets > the filename from your GUI. > > Hope this helps, > > -- > Carsten Haese > http://informixdb.sourceforge.net > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/problems-with-opening-files-due-to-file%27s-path-tp17759531p17787228.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
best way to create a timer/alarm
I am wondering what is the best way to create a timer, like an alarm, once it reaches a time, it triggers an event. I have a way of doing this but it seems like it isn't good at all. If it helps at all I am using a Tkinter, but that probably doesn't mean much. The way I was doing it was using a while loop, and just saying while current time is not = to trigger time, do nothing, and when it is, do event. -- View this message in context: http://www.nabble.com/best-way-to-create-a-timer-alarm-tp17815502p17815502.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
os.startfile() on a mac
So i have a mac and pc, and just found out that os.startfile() doesn't work on a mac. So is there anything like that besides os.system()? -- View this message in context: http://www.nabble.com/os.startfile%28%29-on-a-mac-tp17829335p17829335.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
using urllib2
I have never used the urllib or the urllib2. I really have looked online for help on this issue, and mailing lists, but I can't figure out my problem because people haven't been helping me, which is why I am here! :]. Okay, so basically I want to be able to submit a word to dictionary.com and then get the definitions. However, to start off learning urllib2, I just want to do a simple google search. Before you get mad, what I have found on urllib2 hasn't helped me. Anyway, How would you go about doing this. No, I did not post the html, but I mean if you want, right click on your browser and hit view source of the google homepage. Basically what I want to know is how to submit the values(the search term) and then search for that value. Heres what I know: import urllib2 response = urllib2.urlopen("http://www.google.com/";) html = response.read() print html Now I know that all this does is print the source, but thats about all I know. I know it may be a lot to ask to have someone show/help me, but I really would appreciate it. -- View this message in context: http://www.nabble.com/using-urllib2-tp18150669p18150669.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: using urllib2
Okay, I tried to follow that, and it is kinda hard. But since you obviously know what you are doing, where did you learn this? Or where can I learn this? Maric Michaud wrote: > > Le Friday 27 June 2008 10:43:06 Alexnb, vous avez écrit : >> I have never used the urllib or the urllib2. I really have looked online >> for help on this issue, and mailing lists, but I can't figure out my >> problem because people haven't been helping me, which is why I am here! >> :]. >> Okay, so basically I want to be able to submit a word to dictionary.com >> and >> then get the definitions. However, to start off learning urllib2, I just >> want to do a simple google search. Before you get mad, what I have found >> on >> urllib2 hasn't helped me. Anyway, How would you go about doing this. No, >> I >> did not post the html, but I mean if you want, right click on your >> browser >> and hit view source of the google homepage. Basically what I want to know >> is how to submit the values(the search term) and then search for that >> value. Heres what I know: >> >> import urllib2 >> response = urllib2.urlopen("http://www.google.com/";) >> html = response.read() >> print html >> >> Now I know that all this does is print the source, but thats about all I >> know. I know it may be a lot to ask to have someone show/help me, but I >> really would appreciate it. > > This example is for google, of course using pygoogle is easier in this > case, > but this is a valid example for the general case : > >>>>[207]: import urllib, urllib2 > > You need to trick the server with an imaginary User-Agent. > >>>>[208]: def google_search(terms) : > return urllib2.urlopen(urllib2.Request("http://www.google.com/search?"; > + > urllib.urlencode({'hl':'fr', 'q':terms}), >headers={'User-Agent':'MyNav > 1.0 > (compatible; MSIE 6.0; Linux'}) > ).read() >.: > >>>>[212]: res = google_search("python & co") > > Now you got the whole html response, you'll have to parse it to recover > datas, > a quick & dirty try on google response page : > >>>>[213]: import re > >>>>[214]: [ re.sub('<.+?>', '', e) for e in re.findall('.*?', > res) ] > ...[229]: > ['Python Gallery', > 'Coffret Monty Python And Co 3 DVD : La Premi\xe8re folie des Monty ...', > 'Re: os x, panther, python & co: msg#00041', > 'Re: os x, panther, python & co: msg#00040', > 'Cardiff Web Site Design, Professional web site design services ...', > 'Python Properties', > 'Frees < Programs < Python < Bin-Co', > 'Torb: an interface between Tcl and CORBA', > 'Royal Python Morphs', > 'Python & Co'] > > > -- > _ > > Maric Michaud > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/using-urllib2-tp18150669p18160312.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: using urllib2
I have read that multiple times. It is hard to understand but it did help a little. But I found a bit of a work-around for now which is not what I ultimately want. However, even when I can get to the page I want lets say, "Http://dictionary.reference.com/browse/cheese", I look on firebug, and extension and see the definition in javascript, 1. the curd of milk separated from the whey and prepared in many ways as a food. Jeff McNeil-2 wrote: > > > the problem being that if I use code like this to get the html of that > page in python: > > response = urllib2.urlopen("the webiste") > html = response.read() > print html > > then, I get a bunch of stuff, but it doesn't show me the code with the > table that the definition is in. So I am asking how do I access this > javascript. Also, if someone could point me to a better reference than the > last one, because that really doesn't tell me much, whether it be a book > or anything. > > > > I stumbled across this a while back: > http://www.voidspace.org.uk/python/articles/urllib2.shtml. > It covers quite a bit. The urllib2 module is pretty straightforward > once you've used it a few times. Some of the class naming and whatnot > takes a bit of getting used to (I found that to be the most confusing > bit). > > On Jun 27, 1:41 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> Okay, I tried to follow that, and it is kinda hard. But since you >> obviously >> know what you are doing, where did you learn this? Or where can I learn >> this? >> >> >> >> >> >> Maric Michaud wrote: >> >> > Le Friday 27 June 2008 10:43:06 Alexnb, vous avez écrit : >> >> I have never used the urllib or the urllib2. I really have looked >> online >> >> for help on this issue, and mailing lists, but I can't figure out my >> >> problem because people haven't been helping me, which is why I am >> here! >> >> :]. >> >> Okay, so basically I want to be able to submit a word to >> dictionary.com >> >> and >> >> then get the definitions. However, to start off learning urllib2, I >> just >> >> want to do a simple google search. Before you get mad, what I have >> found >> >> on >> >> urllib2 hasn't helped me. Anyway, How would you go about doing this. >> No, >> >> I >> >> did not post the html, but I mean if you want, right click on your >> >> browser >> >> and hit view source of the google homepage. Basically what I want to >> know >> >> is how to submit the values(the search term) and then search for that >> >> value. Heres what I know: >> >> >> import urllib2 >> >> response = urllib2.urlopen("http://www.google.com/";) >> >> html = response.read() >> >> print html >> >> >> Now I know that all this does is print the source, but thats about all >> I >> >> know. I know it may be a lot to ask to have someone show/help me, but >> I >> >> really would appreciate it. >> >> > This example is for google, of course using pygoogle is easier in this >> > case, >> > but this is a valid example for the general case : >> >> >>>>[207]: import urllib, urllib2 >> >> > You need to trick the server with an imaginary User-Agent. >> >> >>>>[208]: def google_search(terms) : >> > return >> urllib2.urlopen(urllib2.Request("http://www.google.com/search?"; >> > + >> > urllib.urlencode({'hl':'fr', 'q':terms}), >> >headers={'User-Agent':'MyNav >> > 1.0 >> > (compatible; MSIE 6.0; Linux'}) >> > ).read() >> >.: >> >> >>>>[212]: res = google_search("python & co") >> >> > Now you got the whole html response, you'll have to parse it to recover >> > datas, >> > a quick & dirty try on google response page : >> >> >>>>[213]: import re >> >> >>>>[214]: [ re.sub('<.+?>', '', e) for e in re.findall('> class=r>.*?', >> > res) ] >> > ...[229]: >> > ['Python Gallery', >> > 'Coffret Monty Python And Co 3 DVD : La Premi\xe8re folie des Monty >> ...', >> > 'Re: os x, panther, python & co: msg#00041', >> > 'Re: os x, panther, python & co: msg#00040', >> > 'Cardiff Web Site Design, Professional web site design services ...', >> > 'Python Properties', >> > 'Frees < Programs < Python < Bin-Co', >> > 'Torb: an interface between Tcl and CORBA', >> > 'Royal Python Morphs', >> > 'Python & Co'] >> >> > -- >> > _ >> >> > Maric Michaud >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> -- >> View this message in >> context:http://www.nabble.com/using-urllib2-tp18150669p18160312.html >> Sent from the Python - python-list mailing list archive at Nabble.com. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/using-urllib2-tp18150669p18165634.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: using urllib2
I have read that multiple times. It is hard to understand but it did help a little. But I found a bit of a work-around for now which is not what I ultimately want. However, even when I can get to the page I want lets say, "Http://dictionary.reference.com/browse/cheese", I look on firebug, and extension and see the definition in javascript, 1. the curd of milk separated from the whey and prepared in many ways as a food. the problem being that if I use code like this to get the html of that page in python: response = urllib2.urlopen("the webiste") html = response.read() print html then, I get a bunch of stuff, but it doesn't show me the code with the table that the definition is in. So I am asking how do I access this javascript. Also, if someone could point me to a better reference than the last one, because that really doesn't tell me much, whether it be a book or anything. Jeff McNeil-2 wrote: > > I stumbled across this a while back: > http://www.voidspace.org.uk/python/articles/urllib2.shtml. > It covers quite a bit. The urllib2 module is pretty straightforward > once you've used it a few times. Some of the class naming and whatnot > takes a bit of getting used to (I found that to be the most confusing > bit). > > On Jun 27, 1:41 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> Okay, I tried to follow that, and it is kinda hard. But since you >> obviously >> know what you are doing, where did you learn this? Or where can I learn >> this? >> >> >> >> >> >> Maric Michaud wrote: >> >> > Le Friday 27 June 2008 10:43:06 Alexnb, vous avez écrit : >> >> I have never used the urllib or the urllib2. I really have looked >> online >> >> for help on this issue, and mailing lists, but I can't figure out my >> >> problem because people haven't been helping me, which is why I am >> here! >> >> :]. >> >> Okay, so basically I want to be able to submit a word to >> dictionary.com >> >> and >> >> then get the definitions. However, to start off learning urllib2, I >> just >> >> want to do a simple google search. Before you get mad, what I have >> found >> >> on >> >> urllib2 hasn't helped me. Anyway, How would you go about doing this. >> No, >> >> I >> >> did not post the html, but I mean if you want, right click on your >> >> browser >> >> and hit view source of the google homepage. Basically what I want to >> know >> >> is how to submit the values(the search term) and then search for that >> >> value. Heres what I know: >> >> >> import urllib2 >> >> response = urllib2.urlopen("http://www.google.com/";) >> >> html = response.read() >> >> print html >> >> >> Now I know that all this does is print the source, but thats about all >> I >> >> know. I know it may be a lot to ask to have someone show/help me, but >> I >> >> really would appreciate it. >> >> > This example is for google, of course using pygoogle is easier in this >> > case, >> > but this is a valid example for the general case : >> >> >>>>[207]: import urllib, urllib2 >> >> > You need to trick the server with an imaginary User-Agent. >> >> >>>>[208]: def google_search(terms) : >> > return >> urllib2.urlopen(urllib2.Request("http://www.google.com/search?"; >> > + >> > urllib.urlencode({'hl':'fr', 'q':terms}), >> >headers={'User-Agent':'MyNav >> > 1.0 >> > (compatible; MSIE 6.0; Linux'}) >> > ).read() >> >.: >> >> >>>>[212]: res = google_search("python & co") >> >> > Now you got the whole html response, you'll have to parse it to recover >> > datas, >> > a quick & dirty try on google response page : >> >> >>>>[213]: import re >> >> >>>>[214]: [ re.sub('<.+?>', '', e) for e in re.findall('> class=r>.*?', >> > res) ] >> > ...[229]: >> > ['Python Gallery', >> > 'Coffret Monty Python And Co 3 DVD : La Premi\xe8re folie des Monty >> ...', >> > 'Re: os x, panther, python & co: msg#00041', >> > 'Re: os x, panther, python & co: msg#00040', >> > 'Cardiff Web Site Design, Professional web site design services ...', >> > 'Python Properties', >> > 'Frees < Programs < Python < Bin-Co', >> > 'Torb: an interface between Tcl and CORBA', >> > 'Royal Python Morphs', >> > 'Python & Co'] >> >> > -- >> > _ >> >> > Maric Michaud >> > -- >> >http://mail.python.org/mailman/listinfo/python-list >> >> -- >> View this message in >> context:http://www.nabble.com/using-urllib2-tp18150669p18160312.html >> Sent from the Python - python-list mailing list archive at Nabble.com. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/using-urllib2-tp18150669p18165692.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: using urllib2
Okay, so I copied your code(and just so you know I am on a mac right now and i am using pydev in eclipse), and I got these errors, any idea what is up? Traceback (most recent call last): File "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", line 14, in print list(get_defs("cheese")) File "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", line 9, in get_defs dictionary.reference.com/search?q=%s' % term)) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib.py", line 82, in urlopen return opener.open(url) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib.py", line 190, in open return getattr(self, name)(url) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib.py", line 325, in open_http h.endheaders() File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", line 856, in endheaders self._send_output() File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", line 728, in _send_output self.send(msg) File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", line 695, in send self.connect() File "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", line 663, in connect socket.SOCK_STREAM): IOError: [Errno socket error] (8, 'nodename nor servname provided, or not known') Sorry if it is hard to read. Jeff McNeil-2 wrote: > > Well, what about pulling that data out using Beautiful soup? If you > know the table name and whatnot, try something like this: > > #!/usr/bin/python > > import urllib > from BeautifulSoup import BeautifulSoup > > > def get_defs(term): > soup = BeautifulSoup(urllib.urlopen('http:// > dictionary.reference.com/search?q=%s' % term)) > > for tabs in soup.findAll('table', {'class': 'luna-Ent'}): > yield tabs.findAll('td')[-1].contents[-1].string > > print list(get_defs("frog")) > > [EMAIL PROTECTED]:~$ python test.py > [u'any tailless, stout-bodied amphibian of the order Anura, including > the smooth, moist-skinned frog species that live in a damp or > semiaquatic habitat and the warty, drier-skinned toad species that are > mostly terrestrial as adults. ', u' ', u' ', u'a French person or a > person of French descent. ', u'a small holder made of heavy material, > placed in a bowl or vase to hold flower stems in position. ', u'a > recessed panel on one of the larger faces of a brick or the like. ', > u' ', u'to hunt and catch frogs. ', u'French or Frenchlike. ', u'an > ornamental fastening for the front of a coat, consisting of a button > and a loop through which it passes. ', u'a sheath suspended from a > belt and supporting a scabbard. ', u'a device at the intersection of > two tracks to permit the wheels and flanges on one track to cross or > branch from the other. ', u'a triangular mass of elastic, horny > substance in the middle of the sole of the foot of a horse or related > animal. '] > > HTH, > > Jeff > > On Jun 27, 7:28 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> I have read that multiple times. It is hard to understand but it did help >> a >> little. But I found a bit of a work-around for now which is not what I >> ultimately want. However, even when I can get to the page I want lets >> say, >> "Http://dictionary.reference.com/browse/cheese", I look on firebug, and >> extension and see the definition in javascript, >> >> >> >> >> 1. >> the curd of milk separated from the whey and prepared in >> many ways as a food. >> >> >> >> Jeff McNeil-2 wrote: >> >> > the problem being that if I use code like this to get the html of that >> > page in python: >> >> > response = urllib2.urlopen("the webiste") >> > html = response.read() >> > print html >> >> > then, I get a bunch of stuff, but it doesn't show me the code with the >> > table that the definition is in. So I am asking how do I access this >> > javascript. Also, if someone could point me to a better reference than >> the >> > last one, because that really doesn't tell me much, whether it be a >> book >> > or anything. >> >> > I stumbled across this a while back: >> >http://www.voidspace
Re: using urllib2
No I figured it out. I guess I never knew that you aren't supposed to split a url like "http://www.goo\ gle.com" But I did and it gave me all those errors. Anyway, I had a question. On the original code you had this for loop: for tabs in soup.findAll('table', {'class': 'luna-Ent'}): yield tabs.findAll('td')[-1].contents[-1].string I hate to be a pain, but I was looking at the BeautifulSoup docs, and found the findAll thing. But I want to know why you put "for tabs," also why you need the "'table', {'class': 'luna-Ent'}):" Like why the curly braces and whatnot? Jeff McNeil-2 wrote: > > On Jun 27, 10:26 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> Okay, so I copied your code(and just so you know I am on a mac right now >> and >> i am using pydev in eclipse), and I got these errors, any idea what is >> up? >> >> Traceback (most recent call last): >> File >> "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", >> line 14, in >> print list(get_defs("cheese")) >> File >> "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", >> line 9, in get_defs >> dictionary.reference.com/search?q=%s' % term)) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib.py", >> line 82, in urlopen >> return opener.open(url) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib.py", >> line 190, in open >> return getattr(self, name)(url) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/urllib.py", >> line 325, in open_http >> h.endheaders() >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", >> line 856, in endheaders >> self._send_output() >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", >> line 728, in _send_output >> self.send(msg) >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", >> line 695, in send >> self.connect() >> File >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/httplib.py", >> line 663, in connect >> socket.SOCK_STREAM): >> IOError: [Errno socket error] (8, 'nodename nor servname provided, or not >> known') >> >> Sorry if it is hard to read. >> >> >> >> Jeff McNeil-2 wrote: >> >> > Well, what about pulling that data out using Beautiful soup? If you >> > know the table name and whatnot, try something like this: >> >> > #!/usr/bin/python >> >> > import urllib >> > from BeautifulSoup import BeautifulSoup >> >> > def get_defs(term): >> > soup = BeautifulSoup(urllib.urlopen('http:// >> > dictionary.reference.com/search?q=%s' % term)) >> >> > for tabs in soup.findAll('table', {'class': 'luna-Ent'}): >> > yield tabs.findAll('td')[-1].contents[-1].string >> >> > print list(get_defs("frog")) >> >> > [EMAIL PROTECTED]:~$ python test.py >> > [u'any tailless, stout-bodied amphibian of the order Anura, including >> > the smooth, moist-skinned frog species that live in a damp or >> > semiaquatic habitat and the warty, drier-skinned toad species that are >> > mostly terrestrial as adults. ', u' ', u' ', u'a French person or a >> > person of French descent. ', u'a small holder made of heavy material, >> > placed in a bowl or vase to hold flower stems in position. ', u'a >> > recessed panel on one of the larger faces of a brick or the like. ', >> > u' ', u'to hunt and catch frogs. ', u'French or Frenchlike. ', u'an >> > ornamental fastening for the front of a coat, consisting of a button >> > and a loop through which it passes. ', u'a sheath suspended from a >> > belt and supporting a scabbard. ', u'a device at the intersection of >> > two tracks to permit the wheels and flanges on one track to cross or >> > branch from the other. ', u'a triangular mass of elastic, horny >> > substance in the middle of the sole of the foot of a horse or related >> > animal. '] >>
Re: using urllib2
Okay, so i've hit a new snag and can't seem to figure out what is wrong. What is happening is the first 4 definitions of the word "simple" don't show up. The html is basicly the same, with the exception of noun turning into adj. Ill paste the html of the word cheese, and then the one for simple, and the code I am using to do the work. line of html for the 2nd def of cheese: 2.a definite mass of this substance, often in the shape of a wheel or cylinder. line of html for the 2nd def of simple: 2.not elaborate or artificial; plain: a simple style. code: import urllib from BeautifulSoup import BeautifulSoup def get_defs(term): soup = BeautifulSoup(urllib.urlopen('http://dictionary.reference.com/search?q=%s' % term)) for tabs in soup.findAll('table', {'class': 'luna-Ent'}): yield tabs.findAll('td')[-1].contents[-1].string word = raw_input("What word would you like to define: ") mainList = list(get_defs(word)) n=0 q = 1 for x in mainList: print str(q)+". "+str(mainList[n]) q=q+1 n=n+1 Now, I don't think it is the italics because one of the definitions that worked had them in it in the same format. Any Ideas??! Jeff McNeil-2 wrote: > > On Jun 29, 12:50 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> No I figured it out. I guess I never knew that you aren't supposed to >> split a >> url like "http://www.goo\ >> gle.com" But I did and it gave me all those errors. Anyway, I had a >> question. On the original code you had this for loop: >> >> for tabs in soup.findAll('table', {'class': 'luna-Ent'}): >> yield tabs.findAll('td')[-1].contents[-1].string >> >> I hate to be a pain, but I was looking at the BeautifulSoup docs, and >> found >> the findAll thing. But I want to know why you put "for tabs," also why >> you >> need the "'table', {'class': 'luna-Ent'}):" Like why the curly braces and >> whatnot? >> >> Jeff McNeil-2 wrote: >> >> > On Jun 27, 10:26 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> >> Okay, so I copied your code(and just so you know I am on a mac right >> now >> >> and >> >> i am using pydev in eclipse), and I got these errors, any idea what is >> >> up? >> >> >> Traceback (most recent call last): >> >> File >> >> "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", >> >> line 14, in >> >> print list(get_defs("cheese")) >> >> File >> >> "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", >> >> line 9, in get_defs >> >> dictionary.reference.com/search?q=%s' % term)) >> >> File >> >> >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/url >> lib.py", >> >> line 82, in urlopen >> >> return opener.open(url) >> >> File >> >> >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/url >> lib.py", >> >> line 190, in open >> >> return getattr(self, name)(url) >> >> File >> >> >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/url >> lib.py", >> >> line 325, in open_http >> >> h.endheaders() >> >> File >> >> >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/htt >> plib.py", >> >> line 856, in endheaders >> >> self._send_output() >> >> File >> >> >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/htt >> plib.py", >> >> line 728, in _send_output >> >> self.send(msg) >> >> File >> >> >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/htt >> plib.py", >> >> line 695, in send >> >> self.connect() >> >> File >> >> >> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/htt >> plib.py", >> >> line 663, in connect >> >> socket.SOCK_STREAM): >> >> IOError: [Errno socket error] (8, 'nodename nor servname provided, or >> not >> >> known') >> >> >> Sorry if it is hard to read. >> >> >> Jeff McNeil-2 wrote: >> >> >> > Well,
Re: using urllib2
Actually after looking at this, the code is preactically the same, except the definitions. So what COULD be going wrong here? Alexnb wrote: > > Okay, so i've hit a new snag and can't seem to figure out what is wrong. > What is happening is the first 4 definitions of the word "simple" don't > show up. The html is basicly the same, with the exception of noun turning > into adj. Ill paste the html of the word cheese, and then the one for > simple, and the code I am using to do the work. > > line of html for the 2nd def of cheese: > > 2. valign="top">a definite mass of this substance, often in the shape of a > wheel or cylinder. > > line of html for the 2nd def of simple: > > 2. valign="top">not elaborate or artificial; plain: a simple style. > > > code: > > import urllib > from BeautifulSoup import BeautifulSoup > > > def get_defs(term): > soup = > BeautifulSoup(urllib.urlopen('http://dictionary.reference.com/search?q=%s' > % term)) > > for tabs in soup.findAll('table', {'class': 'luna-Ent'}): > yield tabs.findAll('td')[-1].contents[-1].string > > word = raw_input("What word would you like to define: ") > > mainList = list(get_defs(word)) > > n=0 > q = 1 > > for x in mainList: > print str(q)+". "+str(mainList[n]) > q=q+1 > n=n+1 > > Now, I don't think it is the italics because one of the definitions that > worked had them in it in the same format. Any Ideas??! > > > Jeff McNeil-2 wrote: >> >> On Jun 29, 12:50 pm, Alexnb <[EMAIL PROTECTED]> wrote: >>> No I figured it out. I guess I never knew that you aren't supposed to >>> split a >>> url like "http://www.goo\ >>> gle.com" But I did and it gave me all those errors. Anyway, I had a >>> question. On the original code you had this for loop: >>> >>> for tabs in soup.findAll('table', {'class': 'luna-Ent'}): >>> yield tabs.findAll('td')[-1].contents[-1].string >>> >>> I hate to be a pain, but I was looking at the BeautifulSoup docs, and >>> found >>> the findAll thing. But I want to know why you put "for tabs," also why >>> you >>> need the "'table', {'class': 'luna-Ent'}):" Like why the curly braces >>> and >>> whatnot? >>> >>> Jeff McNeil-2 wrote: >>> >>> > On Jun 27, 10:26 pm, Alexnb <[EMAIL PROTECTED]> wrote: >>> >> Okay, so I copied your code(and just so you know I am on a mac right >>> now >>> >> and >>> >> i am using pydev in eclipse), and I got these errors, any idea what >>> is >>> >> up? >>> >>> >> Traceback (most recent call last): >>> >> File >>> >> "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", >>> >> line 14, in >>> >> print list(get_defs("cheese")) >>> >> File >>> >> "/Users/Alex/Documents/workspace/beautifulSoup/src/firstExample.py", >>> >> line 9, in get_defs >>> >> dictionary.reference.com/search?q=%s' % term)) >>> >> File >>> >> >>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/url >>> lib.py", >>> >> line 82, in urlopen >>> >> return opener.open(url) >>> >> File >>> >> >>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/url >>> lib.py", >>> >> line 190, in open >>> >> return getattr(self, name)(url) >>> >> File >>> >> >>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/url >>> lib.py", >>> >> line 325, in open_http >>> >> h.endheaders() >>> >> File >>> >> >>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/htt >>> plib.py", >>> >> line 856, in endheaders >>> >> self._send_output() >>> >> File >>> >> >>> "/System/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/htt >>> plib.py", >>> >> line 728, in _send_output >>> >> self.send(msg) >>> >>
Re: using urllib2
Okay, now I ran in it the shell, and this is what happened: >>> for tabs in soup.findAll('table', {'class': 'luna-Ent'}): ... tabs.findAll('td')[-1].contents[-1].string ... u' ' u' ' u' ' u' ' u' ' u'not complex or compound; single. ' u' ' u' ' u' ' u' ' u' ' u'inconsequential or rudimentary. ' u'unlearned; ignorant. ' u' ' u'unsophisticated; naive; credulous. ' u' ' u'not mixed. ' u' ' u'not mixed. ' u' ' u' ' u' ' u' ' u'). ' u' ' u'(of a lens) having two optical surfaces only. ' u'an ignorant, foolish, or gullible person. ' u'something simple, unmixed, or uncompounded. ' u'cords for controlling the warp threads in forming the shed on draw-looms. ' u'a person of humble origins; commoner. ' u' ' >>> However, the definitions are there. I printed the actual soup and they were there in the format they always were in. So what is the deal!?! >>> soup.findAll('table', {'class': 'luna-Ent'}) [1.easy to understand, deal with, use, etc.: a simple matter; simple tools. See there is the first one in the shell, I mean it is there, but the for loop can't find it. I am wondering, because the above soup.findAll('table'..etc. makes it a list. Do you think that has anything to do with the problem? Alexnb wrote: > > Actually after looking at this, the code is preactically the same, except > the definitions. So what COULD be going wrong here? > > Also, I ran the program and decided to print the whole list of definitions > straight off BeautifulSoup, and I got an interesting result: > > What word would you like to define: simple > [u' ', u' ', u' ', u' ', u' ', u'not complex or compound; single. > > those are the first 5 definitions. and later on, it does the same thing. > it only sees a space, any ideas? > > Alexnb wrote: >> >> Okay, so i've hit a new snag and can't seem to figure out what is wrong. >> What is happening is the first 4 definitions of the word "simple" don't >> show up. The html is basicly the same, with the exception of noun turning >> into adj. Ill paste the html of the word cheese, and then the one for >> simple, and the code I am using to do the work. >> >> line of html for the 2nd def of cheese: >> >> 2.> valign="top">a definite mass of this substance, often in the shape of a >> wheel or cylinder. >> >> line of html for the 2nd def of simple: >> >> 2.> valign="top">not elaborate or artificial; plain: a simple style. >> >> >> code: >> >> import urllib >> from BeautifulSoup import BeautifulSoup >> >> >> def get_defs(term): >> soup = >> BeautifulSoup(urllib.urlopen('http://dictionary.reference.com/search?q=%s' >> % term)) >> >> for tabs in soup.findAll('table', {'class': 'luna-Ent'}): >> yield tabs.findAll('td')[-1].contents[-1].string >> >> word = raw_input("What word would you like to define: ") >> >> mainList = list(get_defs(word)) >> >> n=0 >> q = 1 >> >> for x in mainList: >> print str(q)+". "+str(mainList[n]) >> q=q+1 >> n=n+1 >> >> Now, I don't think it is the italics because one of the definitions that >> worked had them in it in the same format. Any Ideas??! >> >> >> Jeff McNeil-2 wrote: >>> >>> On Jun 29, 12:50 pm, Alexnb <[EMAIL PROTECTED]> wrote: >>>> No I figured it out. I guess I never knew that you aren't supposed to >>>> split a >>>> url like "http://www.goo\ >>>> gle.com" But I did and it gave me all those errors. Anyway, I had a >>>> question. On the original code you had this for loop: >>>> >>>> for tabs in soup.findAll('table', {'class': 'luna-Ent'}): >>>> yield tabs.findAll('td')[-1].contents[-1].string >>>> >>>> I hate to be a pain, but I was looking at the BeautifulSoup docs, and >>>> found >>>> the findAll thing. But I want to know why you put "for tabs," also why >>>> you >>>> need the "'table', {'clas
Problem with a for loop and a list
I am not sure what is going on here. Here is the code that is being run: def getWords(self): self.n=0 for entry in self.listBuffer: self.wordList[self.n] = entry.get() self.n=self.n+1 print self.wordList This is the "listBuffer" that you see: self.listBuffer=[self.e1, self.e2, self.e3, self.e4, self.e5, self.e6, self.e7, self.e8, self.e9, self.e10, self.e11, self.e12, self.e13, self.e14] (side note, those are all tkinter entry widgets, and the get() function gets the text) this is the error the interpreter is giving me when I run it: self.getWords() File "C:/Documents and Settings/Alex/My Documents/PYTHON/DictionaryApp/The GUI.py", line 153, in getWords self.wordList[self.n] = entry.get() IndexError: list assignment index out of range I have no idea what "list assignment index out of range means?!?! -- View this message in context: http://www.nabble.com/Problem-with-a-for-loop-and-a-list-tp18232298p18232298.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with a for loop and a list
well okay, so what can I do? A.T.Hofkamp-3 wrote: > > On 2008-07-02, Alexnb <[EMAIL PROTECTED]> wrote: >> I have no idea what "list assignment index out of range means?!?! > > You are assigning a value to a non-existing list element, as in > >>>> x = [1] >>>> x[2] = 4 > Traceback (most recent call last): > File "", line 1, in ? > IndexError: list assignment index out of range > > > Albert > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Problem-with-a-for-loop-and-a-list-tp18232298p18232528.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with a for loop and a list
Actually I tried that and had no sucsess, but I just figured it out. I set every value in wordList to 'None' and so even if all the entry fields aren't taken up, they go to '', so I can tell what is and what isn't taken up, and get the string of the ones that are taken up. Terry Reedy wrote: > > > > Alexnb wrote: >> I am not sure what is going on here. Here is the code that is being run: >> >> def getWords(self): >> self.n=0 >> for entry in self.listBuffer: >> self.wordList[self.n] = entry.get() > > And what does self.wordList begin as? If {}, then the assignemt is > invalid. Perhaps you want self.wordList.append(entry.get()) > >> self.n=self.n+1 > > Is this supposed to be incremented once per entry or once per > getWords()? If the former, you would overwrite previous assignment (if > it worked) for every item except the last. > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/Problem-with-a-for-loop-and-a-list-tp18232298p18232688.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Testing for an empty list
Okay this is a simple question I just don't know how. If I have a list, say: funList = [] and after a while something possible should have been appended to it, but wasn't. How can I test if that list is empty. -- View this message in context: http://www.nabble.com/Testing-for-an-empty-list-tp18268092p18268092.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Trouble with Tkinter text margins
I am writing a program in which there is a textbox and in it the program auto inputs a series of words, and definitions for each word. I want to make it formatted nicely to where the word is indented, and the definitions indented even more. I don't even know how to make the margins work. I have read all the documentation but just need an example so that will help. But my bigger issue is that the way I have written it is like this: for entry in WordList: the definions go in. While that is very dumbed down, that is the gist. Meaning the words to be defined are in "wordlist" and for each entry it prints the entry and the definition. My problem is that I want the lmargin1 to be indented a little, and that will be the margin where the words are, and lmargin2 to be indented even further, and that will be where the definitions go. I want it to look like this: word: definition1 definition2 word2: definition1 and so on. So I need some help trying to figure out how to make this work with the for loop. -- View this message in context: http://www.nabble.com/Trouble-with-Tkinter-text-margins-tp18325944p18325944.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Help with using findAll() in BeautifulSoup
Okay, I am not sure if there is a better way of doing this than findAll() but that is how I am doing it right now. I am making an app that screen scapes dictionary.com for definitions. However, I would like to have the type of the word for each definition. For example if def1 and def2 are noun defintions but def3 isn't: noun def1 def2 verb def3 Something like that. Now I can get the definitions just fine. But the problem comes when I want to get the type. I can get the types, but I don't know for what definitions they go with. So I can get noun and verb, but for all I know noun is def1, and verb is 2 and 3. I am wondering if there is a way to use findAll() but like stop once it hits a certain thing, or a way to do just that. for example, if I have noun verb I want to be able to do like findAll('span', {'class': 'pg'}), but tell me how many things are after it, or before the next so I know how many defintions it has. Here is the code I am using(I used "cheese" because that is kinda my test word for everything in the app.): import urllib from BeautifulSoup import BeautifulSoup class defWord: def __init__(self, word): self.word = word def get_types(term): soup = BeautifulSoup(urllib.urlopen('http://dictionary.reference.com/search?q=%s' % term)) for tabs in soup.findAll('span', {'class': 'pg'}): yield tabs.contents[0].string self.mainList = list(get_types(self.word)) print self.mainList type = defWord("cheese") I don't know if this is really something anyone can help me fix or if I have to do it on my own. But I would love some help. -- View this message in context: http://www.nabble.com/Help-with-using-findAll%28%29-in-BeautifulSoup-tp18415792p18415792.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Help with BeautifulSoup
Okay, heres the general idea of the html I have to work with: noun verb Okay, I left off some stuff. But what I need to do is get what is inside each and then each . But the key is that I need everything in the EXACT order that it would be in the html. I can easily get the tables but it is the span's than I am having trouble with. -- View this message in context: http://www.nabble.com/Help-with-BeautifulSoup-tp18416200p18416200.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Help with BeautifulSoup
Michiel Overtoom wrote: > > Alex wrote... >> >>Okay, heres the general idea of the html I have to work with: >> >> >> noun >> >> >> >> >> verb >> >> >> >> >> >>Okay, I left off some stuff. > > I wish you didn't, or at least provided an URL where I can get the page > which you are trying to parse. Now I don't have a valid testcase to > tinker > with. And maybe you can also show your code which you already came up > with. > > >> I can easily get the tables but it is the span's than I am having trouble > with. > > I can't see any SPAN tags in the example you provided. > > Greetings, > > -- > "The ability of the OSS process to collect and harness > the collective IQ of thousands of individuals across > the Internet is simply amazing." - Vinod Vallopillil > http://www.catb.org/~esr/halloween/halloween4.html > > -- > http://mail.python.org/mailman/listinfo/python-list > > Oh, well sorry, I wrote the span tags, but they didn't show up. But it was around the noun. Here is the code I have to get the definitions alone: import urllib from BeautifulSoup import BeautifulSoup class defWord: def __init__(self, word): self.word = word def get_defs(term): soup = BeautifulSoup(urllib.urlopen('http://dictionary.reference.com/search?q=%s' % term)) for tabs in soup.findAll('table', {'class': 'luna-Ent'}): yield tabs.findAll('td')[-1].contents[0].string self.mainList = list(get_defs(self.word)) Theres a bit more to it, but it doesn't matter here, and so if you look I am using dictionary.com as the website. If you look at the html, the "" tags are where the type of the word is and that is what I need, in order. Or if I can figure out how many tags are inbetween each "" tag, that too would work. If you need anything else, feel free to ask! -- View this message in context: http://www.nabble.com/Re%3A-Help-with-BeautifulSoup-tp18418004p18423003.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
like py2exe, but on a mac
Hi All I am wondering what I can do to turn a python app (.py) into a mac OSX applicaiton (.app). Just like py2exe does. But I am also wondering since in your applications folder on macs it usually doesn't have an actual folder for each app. Rather an icon. so for firefox, you just see the icon. Unlike windows where you have a folder with everything, and the actual program is in it. where is all the application info stored? just in the .app? Finally whether or not there is an app like py2exe for mac, is there a way to skip the middle man and turn it straight into a .dmg with the app inside? -- View this message in context: http://www.nabble.com/like-py2exe%2C-but-on-a-mac-tp18424336p18424336.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: like py2exe, but on a mac
Python.Arno wrote: > > > On 13 jul 2008, at 00:39, Alexnb wrote: > >> >> Hi All >> >> I am wondering what I can do to turn a python app (.py) into a mac OSX >> applicaiton (.app). Just like py2exe does. > > i use these: > http://undefined.org/python/py2app.html > http://effbot.org/pyfaq/how-do-i-create-a-pyc-file.htm > >> But I am also wondering since in >> your applications folder on macs it usually doesn't have an actual >> folder >> for each app. Rather an icon. so for firefox, you just see the icon. >> Unlike >> windows where you have a folder with everything, and the actual >> program is >> in it. where is all the application info stored? just in the .app? > > apps on OSX are also folder, yet with the reserved .app extension > the OS then presents this as an app (right click on an app and choose > 'Show package content') > > py2app creates all that for you > > >> Finally >> whether or not there is an app like py2exe for mac, is there a way >> to skip >> the middle man and turn it straight into a .dmg with the app inside? >> -- > > a dmg is a disk image, similar to iso on windows > you can create an empty one with Disk Utility then drop everything in > it's NOT an installer > >> > cheers > Arno > -- > http://mail.python.org/mailman/listinfo/python-list > > Okay, well thank you very much for your help you answered all my questions :) -- View this message in context: http://www.nabble.com/like-py2exe%2C-but-on-a-mac-tp18424336p18424499.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Testing for Internet Connection
Hello internet. I am wondering, is there a simple way to test for Internet connection? If not, what is the hard way :p -- View this message in context: http://www.nabble.com/Testing-for-Internet-Connection-tp18460572p18460572.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for Internet Connection
Ben Finney-2 wrote: > > Alexnb <[EMAIL PROTECTED]> writes: > >> I am wondering, is there a simple way to test for Internet >> connection? If not, what is the hard way :p > > Refine the question: What do you mean by "internet"? It isn't a single > entity. > > Do you mean "some particular internet host responding on a particular > network port"? > > If you can define exactly what you mean by "internet connection", the > test for it becomes correspondingly easier. > > -- > \ “Why should I care about posterity? What's posterity ever done | > `\for me?” —Groucho Marx | > _o__) | > Ben Finney > -- > http://mail.python.org/mailman/listinfo/python-list > Well, really I just need to figure out if I am able to connect to one site. That site is dictionary.com. -- View this message in context: http://www.nabble.com/Testing-for-Internet-Connection-tp18460572p18468350.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for Internet Connection
Troeger Thomas (Ext) wrote: > > Alex Marandon wrote: >> Alexnb wrote: >>> I am wondering, is there a simple way to test for Internet connection? >>> If >>> not, what is the hard way :p >> >> Trying to fetch the homepage from a few major websites (Yahoo, Google, >> etc.)? If all of them are failing, it's very likely that the connection >> is down. You can use urllib2 [1] to accomplish that. >> >> [1] <http://docs.python.org/lib/module-urllib2.html> > > This seems to work and is rather fast and wastes no bandwidth: > > == > #!/usr/bin/python > > import socket, struct > > def check_host(host, port, timeout=1): > """ > Check for connectivity to a certain host. > """ > # assume we have no route. > ret=False > > # connect to host. > try: > # create socket. > sock=socket.socket() > # create timeval structure. > timeval=struct.pack("2I", timeout, 0) > # set socket timeout options. > sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVTIMEO, timeval) > sock.setsockopt(socket.SOL_SOCKET, socket.SO_SNDTIMEO, timeval) > # connect to host. > sock.connect((host, port)) > # abort communications. > sock.shutdown(SHUT_RDWR) > # we have connectivity after all. > ret=True > except: > pass > > # try to close socket in any case. > try: > sock.close() > except: > pass > > return ret > > # main - > > if check_host("www.heise.de", 80): > print "Horray!" > else: > print "We've lost headquarters!" > == > > I hope the code is ok, but there is always something you can do better. > Comments? :) > > Cheers, > Thomas. > -- > http://mail.python.org/mailman/listinfo/python-list > > Thomas this code did not work on google.com and I also tried it with port 443 -- View this message in context: http://www.nabble.com/Testing-for-Internet-Connection-tp18460572p18468756.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for Internet Connection
Alex Marandon-3 wrote: > > Alexnb wrote: >> I am wondering, is there a simple way to test for Internet connection? If >> not, what is the hard way :p > > Trying to fetch the homepage from a few major websites (Yahoo, Google, > etc.)? If all of them are failing, it's very likely that the connection > is down. You can use urllib2 [1] to accomplish that. > > [1] <http://docs.python.org/lib/module-urllib2.html> > -- > http://mail.python.org/mailman/listinfo/python-list > > What exactly do you think will work? I am not sure what you think I should do? If I use urlopen("http://www.google.com";) and I am not connected, I am not going to get an exception, the program will fail. -- View this message in context: http://www.nabble.com/Testing-for-Internet-Connection-tp18460572p18471183.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Testing for connection to a website
Okay, I already made this post, but it kinda got lost. So anyway I need to figure out how to test if the user is able to connect to a specific website. Last time I got pointed to the urllib2 page, but if I do urlopen() and and am not connected, the program stops. So I don't know if that was what you guys wanted me to do, but I don't think so, you guys are smarter than that. So, how can I test for connection to a website. -- View this message in context: http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p18473382.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for connection to a website
Alexnb wrote: > > Okay, I already made this post, but it kinda got lost. So anyway I need to > figure out how to test if the user is able to connect to a specific > website. Last time I got pointed to the urllib2 page, but if I do > urlopen() and and am not connected, the program stops. So I don't know if > that was what you guys wanted me to do, but I don't think so, you guys are > smarter than that. So, how can I test for connection to a website. > Just for anyone looking this up later here is code that works :) from urllib2 import * import urllib2 e = '' req = urllib2.Request('http://www.dictionary.com') try: response = urlopen(req) except HTTPError, e: print e.code except URLError, e: print e.reason if e == '': print "good to go" -- View this message in context: http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p18476597.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for connection to a website
Timothy Grant wrote: > > On Tue, Jul 15, 2008 at 3:48 PM, Alexnb <[EMAIL PROTECTED]> wrote: > >> >> >> >> Alexnb wrote: >> > >> > Okay, I already made this post, but it kinda got lost. So anyway I need >> to >> > figure out how to test if the user is able to connect to a specific >> > website. Last time I got pointed to the urllib2 page, but if I do >> > urlopen() and and am not connected, the program stops. So I don't know >> if >> > that was what you guys wanted me to do, but I don't think so, you guys >> are >> > smarter than that. So, how can I test for connection to a website. >> > >> >> Just for anyone looking this up later here is code that works :) >> >> from urllib2 import * >> import urllib2 >> e = '' >> >> req = urllib2.Request('http://www.dictionary.com') >> try: >>response = urlopen(req) >> >> except HTTPError, e: >>print e.code >> except URLError, e: >>print e.reason >> >> if e == '': >>print "good to go" >> -- >> View this message in context: >> http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p18476597.html >> Sent from the Python - python-list mailing list archive at Nabble.com. >> >> -- >> http://mail.python.org/mailman/listinfo/python-list >> > > I'm glad to see you found the old post and implemented the code suggested > there. > > -- > Stand Fast, > tjg. [Timothy Grant] > > -- > http://mail.python.org/mailman/listinfo/python-list > well I can tel you it didn't work for me. In fact I didn't see the code you posted on there, I ended up figuring it out on my own with a little help from the missing manual for urllib2. Also, being rude is kinda stupid because you don't have to help in the first place... -- View this message in context: http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p18478103.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Testing for connection to a website
Fredrik Lundh wrote: > > Alexnb wrote: > >> e = '' > >> try: >> ... >> except HTTPError, e: >> print e.code >> except URLError, e: >> print e.reason >> >> if e == '': >> print "good to go" > > footnote: here's a better way to test if an exception was raised or not: > > try: > ... > except HTTPError, e: > print e.code > except URLError, e: > print e.reason > else: > print "good to go" > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > Thanks! can't believe I didn't think of that. -- View this message in context: http://www.nabble.com/Testing-for-connection-to-a-website-tp18473382p18493785.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
py2exe issues with pictures and icons
Hello I am sure most of you are familiar with py2exe. I am having a bit of a problem. See the program has a few pictures involved and the .ico it uses for the windows. However, the pictures are stored in the same directory as the source, something like: C:\Docs and settings\me\My docs\python\program. When I run the program for the interpreter, just as a .py, everything works just as it should. However, when I compile the main source as an .exe, and say let a friend try the program. It fails because it is missing the .ico. The catch, is I don't want to have it have to installed, at least at this point, I want it to be able to just run. So how can I make it just run from any computer with the files not being in the immediate directory. If that is not possible, how can I put them in the immediate directory and still make it work. Because that directory may change a lot so the path will change. Just a few questions. I hope someone out there can help me out! -- View this message in context: http://www.nabble.com/py2exe-issues-with-pictures-and-icons-tp18493908p18493908.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe issues with pictures and icons
Mike Driscoll wrote: > > On Jul 16, 1:37 pm, Alexnb <[EMAIL PROTECTED]> wrote: >> Hello >> >> I am sure most of you are familiar with py2exe. I am having a bit of a >> problem. See the program has a few pictures involved and the .ico it uses >> for the windows. However, the pictures are stored in the same directory >> as >> the source, something like: C:\Docs and settings\me\My >> docs\python\program. >> When I run the program for the interpreter, just as a .py, everything >> works >> just as it should. However, when I compile the main source as an .exe, >> and >> say let a friend try the program. It fails because it is missing the >> .ico. >> The catch, is I don't want to have it have to installed, at least at this >> point, I want it to be able to just run. So how can I make it just run >> from >> any computer with the files not being in the immediate directory. If that >> is >> not possible, how can I put them in the immediate directory and still >> make >> it work. Because that directory may change a lot so the path will change. >> >> Just a few questions. I hope someone out there can help me out! >> -- >> View this message in >> context:http://www.nabble.com/py2exe-issues-with-pictures-and-icons-tp1849390... >> Sent from the Python - python-list mailing list archive at Nabble.com. > > > Put the part of the code that needs the ico file(s) into a try/except > block. You could also try reading the py2exe wiki and tutorials. This > one looks like it has relevant data: > > http://www.py2exe.org/index.cgi/CustomIcons > > Mike > -- > http://mail.python.org/mailman/listinfo/python-list > > Well, that may solve the icon problem. But what about getting pictures in there? -- View this message in context: http://www.nabble.com/py2exe-issues-with-pictures-and-icons-tp18493908p18495626.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: py2exe issues with pictures and icons
Alexnb wrote: > > > > Mike Driscoll wrote: >> >> On Jul 16, 1:37 pm, Alexnb <[EMAIL PROTECTED]> wrote: >>> Hello >>> >>> I am sure most of you are familiar with py2exe. I am having a bit of a >>> problem. See the program has a few pictures involved and the .ico it >>> uses >>> for the windows. However, the pictures are stored in the same directory >>> as >>> the source, something like: C:\Docs and settings\me\My >>> docs\python\program. >>> When I run the program for the interpreter, just as a .py, everything >>> works >>> just as it should. However, when I compile the main source as an .exe, >>> and >>> say let a friend try the program. It fails because it is missing the >>> .ico. >>> The catch, is I don't want to have it have to installed, at least at >>> this >>> point, I want it to be able to just run. So how can I make it just run >>> from >>> any computer with the files not being in the immediate directory. If >>> that is >>> not possible, how can I put them in the immediate directory and still >>> make >>> it work. Because that directory may change a lot so the path will >>> change. >>> >>> Just a few questions. I hope someone out there can help me out! >>> -- >>> View this message in >>> context:http://www.nabble.com/py2exe-issues-with-pictures-and-icons-tp1849390... >>> Sent from the Python - python-list mailing list archive at Nabble.com. >> >> >> Put the part of the code that needs the ico file(s) into a try/except >> block. You could also try reading the py2exe wiki and tutorials. This >> one looks like it has relevant data: >> >> http://www.py2exe.org/index.cgi/CustomIcons >> >> Mike >> -- >> http://mail.python.org/mailman/listinfo/python-list >> >> > > Well, that may solve the icon problem. But what about getting pictures in > there? > > Okay, the icon fix didn't really fix it, what it did was make the .exe have the icon as the little picture for the shortcut, but it isn't really a shortcut. Whatever. But, I went and ran it on another computer and this was the error log it created right off the bat. Traceback (most recent call last): File "The GUI.py", line 696, in File "Tkinter.pyc", line 1515, in wm_iconbitmap _tkinter.TclError: bitmap "C:\Documents and Settings\Alex\My Documents\PYTHON\DictionaryApp\Windows.ico" not defined -- View this message in context: http://www.nabble.com/py2exe-issues-with-pictures-and-icons-tp18493908p18495836.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Having trouble with some lists in BeautifulSoup
Okay, what I want to do with this code is to got to thesaurus.reference.com and then search for a word and get the syns for it. Now, I can get the syns, but they are still in html form and some are hyperlinks. But I can't get the contents out. I am not that familiar with BeautifulSoup. So if anyone wants to look over this code(if you run it, it will make a lot more sense) and maybe help me out. side note: if you run it, a list object will print and what I am after is the part that starts: american... Heres the code: import urllib from BeautifulSoup import BeautifulSoup class defSyn: def __init__(self, word): self.word = word def get_syn(term): soup = BeautifulSoup(urllib.urlopen('http://thesaurus.reference.com/search?q=%s' % term)) balls = soup.findAll('table', {'width': '100%'}) print soup.prettify() for tabs in soup.findAll('table', {'width': '100%'}): yield tabs.findAll('td', {'colspan': '2'}) self.mainList = list(get_syn(self.word)) print self.mainList[2] if You have any further questions I would be happy to answer. -- View this message in context: http://www.nabble.com/Having-trouble-with-some-lists-in-BeautifulSoup-tp18497409p18497409.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Need help getting BeautifulSoup contents
The trick to this one is that the html looks something like this: american, /browse/blue blue , /browse/brick brick , brie, cheddar, cheshire, /browse/churn churn , /browse/cottage cottage , /browse/cream cream , dunlop, and it goes on My question is I want everything inside, the contents of each ad the regular text of the . I know I can do like a.contents, but it only gives me the first one, in this case being "blue". I want the contents of each of those and the regular contents of the . Can anyone help? -- View this message in context: http://www.nabble.com/Need-help-getting-BeautifulSoup-contents-tp18501881p18501881.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Getting a unknown word out of a list with no spaces
Hello Lets say I have a string: --a href="/browse/brick"--brick--/a-- The -- needs to be replaced with < or > where applicable. and I want the "brick" out of that string (the second brick that is). How can I get just the "brick" out of that string? -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18502758.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
Alexandr N Zamaraev wrote: > s = '--a href="/browse/brick"--brick--/a--' s > '--a href="/browse/brick"--brick--/a--' ''.join('<%s>' % l if i % 2 == 1 else l for i, l in > enumerate(s.split('--'))) > ' /browse/brick brick ' > > -- > http://mail.python.org/mailman/listinfo/python-list > > I'm sorry, I don't think I was being clear. I replaced the <'s with -- so it would post online w/o actually making a link. I just need to know how to get the "brick" out. -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18503144.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
Alexandr N Zamaraev wrote: > > Alexnb wrote: >>>>>> s = '--a href="/browse/brick"--brick--/a--' >>>>>> s >>> '--a href="/browse/brick"--brick--/a--' >>>>>> ''.join('<%s>' % l if i % 2 == 1 else l for i, l in >>> enumerate(s.split('--'))) >>> ' /browse/brick brick ' >> >> I'm sorry, I don't think I was being clear. I replaced the <'s with -- so >> it >> would post online w/o actually making a link. I just need to know how to >> get >> the "brick" out. > 1) if string really '--a href="/browse/brick"--brick--/a--' > >>> s.split('--', 3)[2] > brick > 2) if string ' /browse/brick brick ' > >>> s.split('>', 1)[1].split('<')[0] > brick > -- > http://mail.python.org/mailman/listinfo/python-list > > Excellent! it works. But I have one more question. How can I test to see if the first character of a string is what I want, for example, how can I test to see if the first char of a string is "<"? -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18503367.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: Getting a unknown word out of a list with no spaces
bearophileHUGS wrote: > > On Jul 17, 9:50 am, Alexnb: >> how can I test to see if the first char of a string is "<"? > > I suggest you to try the interactive shell: > >>>> "hello"[0] > 'h' >>>> "hello"[0] == "<" > False >>>> "hello"[0] == "h" > True >>>> "hello".startswith("h") > True > > Bye, > bearophile > -- > http://mail.python.org/mailman/listinfo/python-list > > really? That's just like C. I thought that it would fail because of the way lists work. Thanks! -- View this message in context: http://www.nabble.com/Getting-a-unknown-word-out-of-a-list-with-no-spaces-tp18502758p18503830.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
simple problem with lists I am just forgetting
Lets say we have this list: funlist = ['a', 'b', 'c'] and lets say I do this: if funlist[4]: print funlist[4] I will get the exception "list index out of range" How can I test if the list item is empty without getting that exception? -- View this message in context: http://www.nabble.com/simple-problem-with-lists-I-am-just-forgetting-tp18762181p18762181.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Testing for the first few letters of a string
Okay, I have a fix for this problem, but it is messy and I think there might be a better way. Heres an example: Lets say I have a string: "My name is alex" and I have another string "My name is alex, and I like pie". I want to test to see if just the "My name is alex" part is there. I don't care about the pie part. My first instinct was to just create a for loop and test for the string like this: n = 0 for x in string1: if string1[n] == string2[n] n = n +0 else: break and then later testing to see what n was = to and figuring out if it got through the whole loop. I feel like there should be an easier way to do this, and probably is. So Does anyone have a suggestion? -- View this message in context: http://www.nabble.com/Testing-for-the-first-few-letters-of-a-string-tp18873375p18873375.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Remove the first few(or any amount really) of letters in a string
Lets say I've got a stirng: blah This is my string blah I want to get rid of the blah's but keep the "This is my string." I know you can do this with a for loop, but that is messy and a pain. So does anyone have any suggestions on how to do this? -- View this message in context: http://www.nabble.com/Remove-the-first-few%28or-any-amount-really%29-of-letters-in-a-string-tp18901736p18901736.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
like a "for loop" for a string
Okay, so lets say you have a list: funList = [1,2,3,4,5] and you do: for x in funList: print x this will print 1-5 But I am wondering is there a way to something like this: funString = "string string string non-string non-string string" and for "string" in funString: print something I know you can't do that; but, is there a way do do something similar that gets the same result? -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022098.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a "for loop" for a string
Ya just an example, to print the numbers 1-5 Fredrik Lundh wrote: > > Alexnb wrote: > >> But I am wondering is there a way to something like this: >> >> funString = "string string string non-string non-string string" >> and >> for "string" in funString: >> print something >> >> I know you can't do that; but, is there a way do do something similar >> that >> gets the same result? > > you seem to have forgotten to specify the result. or did you mean that > the above should print 1-5? > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022155.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a "for loop" for a string
Basically I want the code to be able to pick out how many strings there are and then do something with each, or the number. When I say string I mean how many "strings" are in the string "string string string non-string string" Does that help? Fredrik Lundh wrote: > > Alexnb wrote: > >> Ya just an example, to print the numbers 1-5 > > Sorry, I still don't have the slightest idea what you expect the code to > do. > > > >>>> But I am wondering is there a way to something like this: >>>> >>>> funString = "string string string non-string non-string string" >>>> and >>>> for "string" in funString: >>>> print something >>>> >>>> I know you can't do that; but, is there a way do do something similar >>>> that >>>> gets the same result? > >> >>> you seem to have forgotten to specify the result. or did you mean that >>> the above should print 1-5? > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022694.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: like a "for loop" for a string
Uhm, "string" and "non-string" are just that, words within the string. Here shall I dumb it down for you? string = "yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8" It doesn't matter what is in the string, I want to be able to know exactly how many "yes"'s there are. I also want to know what is after each, regardless of length. So, I want to be able to get "text1", but not "text4" because it is after "no" and I want all of "text5+more Text" because it is after "yes". It is like the yeses are bullet points and I want all the info after them. However, all in one string. Fredrik Lundh wrote: > > Alexnb wrote: > >> Basically I want the code to be able to pick out how many strings there >> are >> and then do something with each, or the number. When I say string I mean >> how >> many "strings" are in the string "string string string non-string string" > > >> Does that help? > > not really, since you haven't defined what "string" and "non-string" are >or how strings are separated from each other, and, for some odd > reason, refuse to provide an actual example that includes both a proper > sample string *and* the output you'd expect. > > please don't use the mailing list to play 20 questions. > > > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/like-a-%22for-loop%22-for-a-string-tp19022098p19022976.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
searching through a string and pulling characters
This is similar to my last post, but a little different. Here is what I would like to do. Lets say I have a text file. The contents look like this, only there is A LOT of the same thing. () A registry mark given by underwriters (as at Lloyd's) to ships in first-class condition. Inferior grades are indicated by A 2 and A 3. () The first three letters of the alphabet, used for the whole alphabet. () In church or chapel style; -- said of compositions sung in the old church style, without instrumental accompaniment; as, a mass a capella, i. e., a mass purely vocal. () Astride; with a part on each side; -- used specif. in designating the position of an army with the wings separated by some line of demarcation, as a river or road. Now, I am talking 1000's of these. I need to do something like this. I will have a number, and what I want to do is go through this text file, just like the example. The trick is this, those "()'s" are what I need to match, so if the number is 245 I need to find the 245th () and then get the all the text from after it until the next (). If you have an idea about the best way to do this I would love your help. If you made it all the way through thanks! ;) -- View this message in context: http://www.nabble.com/searching-through-a-string-and-pulling-characters-tp19039594p19039594.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: searching through a string and pulling characters
Okay, well the point of this program is to steal from the OS X built-in dictionary. While most of the files are hidden this one is not. The "()" You saw actually looks like this: ([I][/I]) only the []'s are <'s and >'s but the forum doesn't take kindly to html. What you saw was exactly how it will always be (by that I am talking about the A 2 A 3 thing) The number is based on the word(s) they type into my program, and then it fetches the number that word is in the list of words and then will search the definitions document and go to the nth def. It probably won't work, but that is the Idea. Also, on a side-note, does anyone know a very simple dictionary site, that isn't dictionary.com or yourdictionary.com. Or, a free dictionary that I can download to have an offline reference? John Machin wrote: > > On Aug 19, 6:40 am, Alexnb <[EMAIL PROTECTED]> wrote: >> This is similar to my last post, > > Oh, goodie goodie goodie, I love guessing games! > >> but a little different. Here is what I would >> like to do. >> >> Lets say I have a text file. The contents look like this, only there is A >> LOT of the same thing. >> >> () A registry mark given by underwriters (as at Lloyd's) to ships in >> first-class condition. Inferior grades are indicated by A 2 and A 3. >> () The first three letters of the alphabet, used for the whole alphabet. >> () In church or chapel style; -- said of compositions sung in the old >> church >> style, without instrumental accompaniment; as, a mass a capella, i. e., a >> mass purely vocal. >> () Astride; with a part on each side; -- used specif. in designating the >> position of an army with the wings separated by some line of demarcation, >> as >> a river or road. > > This looks like the "values" part of an abbreviation/acronym > dictionary ... what has happened to the "keys" part (A1, ABC, AC, ? > astride?, ...) > > Does "()" appear always at the start of a line (perhaps preceded by > some whitespace), or can it appear in the middle of a line? > > Are you sure about "A 2" and "A 3"? I would have expected "A2" and > "A3". In other words, is the above an exact copy of some input or have > you re-typed it? > > "()" is a strange way of delimiting things ... > > OK, here's my guess: You have acquired a database with two tables. > Table K maps e.g. "ABC" to 2. Table V maps 2 to "The first three > letters of the alphabet, used for the whole alphabet." You have used > some utility or done "select '() ' + column2 from V. > >> >> Now, I am talking 1000's of these. I need to do something like this. I >> will >> have a number, and what I want to do is go through this text file, just >> like >> the example. The trick is this, those "()'s" are what I need to match, so >> if >> the number is 245 I need to find the 245th () and then get the all the >> text >> from after it until the next (). If you have an idea about the best way >> to >> do this I would love your help. > > The best way to do this is to write a small simple Python script. I > suggest that you try this, and if you have difficulties, post your > attempt here together with a lucid description of the perceived > problem. > > However searching through a large file (how many Mb?) looking for the > nth occurrence of "()" doesn't sound like a good idea after about the > 10th time you do it. Perhaps it might be worth the extra effort to > process the text file once and insert the results in a (say) SQLite > data base so that later you can do "select column2 from V where > column1 = 245". > > A really silly question: You say "I will have a number" (e.g. 245); > what is the source or provenance of this ordinal? A random number > generator? Inscription on a ticket passed through a wicket? "select > column2 from K where column1 = 'A1'"? IOW, perhaps you may need to > consider the larger problem. > > Cheers, > John > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/searching-through-a-string-and-pulling-characters-tp19039594p19041356.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
Re: searching through a string and pulling characters
If by "What happened when you did:" you mean dictionary.com and yourdictionary.com? Nothing, they work but screen scraping isn't medicore at best. They both work fine (yourdictionary is better for screen scraping) but. I want maybe an offline soloution. But the whole reason for the program is that I can type in 20 words at one time, get them defined and formatted and then save all from my app. So far, all is good, I just need an offline soloution, or one from a database. You say a free dictionary program. But how can I get definitions from another program w/o opening it? Anyway, Ideas? John Machin wrote: > > On Aug 19, 8:34 am, Alexnb <[EMAIL PROTECTED]> wrote: > >> The number is based on the word(s) they type into my program, and then it >> fetches the number that word is in the list of words and then will search >> the definitions document and go to the nth def. It probably won't work, >> but >> that is the Idea. > > Consider (1) an existing (free) dictionary application (2) using a > database, if you feel you must write your own application. > >> >> Also, on a side-note, does anyone know a very simple dictionary site, >> that >> isn't dictionary.com or yourdictionary.com. Or, a free dictionary that I >> can >> download to have an offline reference? > > What happened when you did: > > -- > http://mail.python.org/mailman/listinfo/python-list > > -- View this message in context: http://www.nabble.com/searching-through-a-string-and-pulling-characters-tp19039594p19041720.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
simple Question about using BeautifulSoup
Okay, I have used BeautifulSoup a lot lately, but I am wondering, how do you open a local html file? Usually I do something like this for a url soup = BeautifulSoup(urllib.urlopen('http://www.website.com') but the file extension doesn't work. So how do I open one? -- View this message in context: http://www.nabble.com/simple-Question-about-using-BeautifulSoup-tp19069980p19069980.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list