|
Centipeed posted:I'm thinking, since I'll start coding for my university project after Christmas, that just jumping straight into Python 3.0 is a better idea than 2.6. I've already learned some Python, but it's not ingrained in my head so much that 3.0 will be confusing, and I'd rather learn the new standard than the "old" one, especially since they're releasing it next month. No. Do not jump into python 3000 - Python 3000 is not going to be widely adopted for some time - you're much better off focusing on python 2.6 and using that to build up your skills. Python 3000 is not "that big" of a change from 2.6 that it will make all of your 2.6 knowledge and skills worthless.
|
# ? Nov 23, 2008 15:32 |
|
|
# ? May 14, 2024 05:24 |
|
Centipeed posted:Is this a good idea? You'd be better off reading about the changes in python 3000, because you can adopt some of them in earlier versions of python (at least in your mind). To name but a few, don't use reduce(), always use xrange(), pretty much everything that used to return a list will return an interator, etc. http://docs.python.org/dev/3.0/whatsnew/3.0.html
|
# ? Nov 23, 2008 16:05 |
|
m0nk3yz posted:No. Do not jump into python 3000 - Python 3000 is not going to be widely adopted for some time - you're much better off focusing on python 2.6 and using that to build up your skills. Python 3000 is not "that big" of a change from 2.6 that it will make all of your 2.6 knowledge and skills worthless. This. Python 3000 is cool but (a) it's unclear how long it will need to takeover from current Python (several years seems to be the general consensus), (b) in many ways it's just a tidying up of the language so you won;t be wasting your time with current Python, (c) virtually all the learning resources around are devoted to current Python, and (d) it's unclear to me if anyone is actually using it to build things "out in the wild" as yet.
|
# ? Nov 23, 2008 23:06 |
|
Wow those last three posts are an eye-opener. I was holding off on buying some books, and really diving into python on my own time, until after 3.0 came out. But if the consensus is that it won't be widely used for another year, then I will go ahead and get books written for 2.5 and download the 2.6 build at home. I love how simple the IDLE IDE is. I downloaded netbeans because one of the screenshots made it look like it had lots of pop-up help when writing, but, it sure is complex. Way more than I need.
|
# ? Nov 25, 2008 17:44 |
|
Part of a backup script that I'm writing uses subprocess to call mysqldump. I think it's failing out because the output is too big, but I'm not too sure what to do about it. Here's the relevant part of my script:code:
code:
What's going on here? edit: Just realized that one of my mysqldump options was set wrong, but I corrected that and I still get the same error message. Sock on a Fish fucked around with this message at 18:31 on Nov 25, 2008 |
# ? Nov 25, 2008 18:13 |
|
Sock on a Fish posted:mysqldump Try: code:
|
# ? Nov 25, 2008 18:59 |
|
Janin posted:Try: Sweet, the sql dump is kicking off but it looks like it's not making it into the pipe. tar is sassing me about it: code:
|
# ? Nov 25, 2008 20:56 |
|
that's a common tar error, and although I'm not expert enough to check your command syntax, it usually means you didn't put in the second positional argument of a standard tar command lurchington@example:~$ tar jvcf test.tar.gz tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information. lurchington@example:~$ tar jvcf test.tar.gz test test lurchington@example:~$
|
# ? Nov 25, 2008 21:30 |
|
Welp, it looks like tar doesn't easily take input from stdin. swapping in gzip works just fine. The man page says I can use the f option to specify input from any file object, including stdin. I'd really like to use tar so I can just have a single function for creating archives of both directories and sqldumps, can anyone tell me what's up with tar?
|
# ? Nov 25, 2008 22:09 |
|
Sock on a Fish posted:Welp, it looks like tar doesn't easily take input from stdin. swapping in gzip works just fine. You're invoking it with "-" for the filename?
|
# ? Nov 25, 2008 22:52 |
|
JoeNotCharles posted:You're invoking it with "-" for the filename? Yep. code:
I tried this arrangement instead: code:
code:
|
# ? Nov 25, 2008 23:09 |
|
Sock on a Fish posted:Why, for the love of all that is holy, are you not making a bash script? code:
|
# ? Nov 25, 2008 23:50 |
|
Zombywuf posted:Why, for the love of all that is holy, are you not making a bash script? I haven't done any bash scripting while I have worked with Python, and the script does more than just gzip a sql dump. That's pretty much it. I know that shell scripts are a lot more common for these kind of tasks.
|
# ? Nov 26, 2008 00:32 |
|
Sock on a Fish posted:Yep. I just re-read your code, and Did you try what you're trying to do on the command line, before writing your code? You're trying to make tar create an archive from a bunch of character data. That doesn't make any sense at all, and if you'd tried something like it from the command line first you'd discover that: code:
Furthermore, you're calling external applications to handle what Python has built-in libraries for. If you want to build a tar archive, use tarfile. If you want to compress data, use the gzip or bzip2 modules.
|
# ? Nov 26, 2008 02:49 |
|
Sock on a Fish posted:
code:
tripwire fucked around with this message at 05:26 on Nov 26, 2008 |
# ? Nov 26, 2008 05:09 |
|
Janin posted:I just re-read your code, and Thanks, I didn't realize that tar didn't work that way. The documentation for tar says it'll take any file object as input, but it looks like that's not the whole story. I'll give the python libraries a shot.
|
# ? Nov 26, 2008 05:46 |
|
Sock on a Fish posted:Thanks, I didn't realize that tar didn't work that way. The documentation for tar says it'll take any file object as input, but it looks like that's not the whole story. I'll give the python libraries a shot. Do it the way I showed! 4 lines!
|
# ? Nov 26, 2008 07:18 |
|
I have an XML document that looks like thiscode:
I am using minidom. I already have the XML file in a string. How do I extract the string "dataIwant"? I've tried minidom.parseString(xmlstring).getElementsByTagName('entry')[0] but this just gives me: <DOM Element: entry at 0x5f1af8> You would think this would be easier to find. Edit: minidom.parseString(xmlstring).getElementsByTagName('entry')[0].childNodes[0].toxml() Such a simple operation should not be this complicated... functional fucked around with this message at 03:33 on Nov 29, 2008 |
# ? Nov 26, 2008 22:54 |
|
The DOM is a Java-style API ported to Python, which explains why it's so obtuse. You need to get the entry's child node, which will be a text node, and then retrieve its data:code:
|
# ? Nov 26, 2008 23:02 |
|
functional posted:I am using minidom. I already have the XML file in a string. How do I extract the string "dataIwant"? May I suggest checking out Genshi for your XML parsing? Its paradigm of operating on XML as streams can be really great for extracting things. (Just give it an X-Path statement for what you want, and shazam!) It has it's own set of pros and cons, but I've done an HTML "scraper" with it and found it to be really delightful to work with. tbradshaw fucked around with this message at 09:02 on Nov 27, 2008 |
# ? Nov 27, 2008 03:12 |
|
I will second the recommendation for Genshi, it is a really great tool. Here's how to do what you want in Genshi:code:
jonypawks fucked around with this message at 08:32 on Nov 27, 2008 |
# ? Nov 27, 2008 08:30 |
|
lxml also works pretty well, but I did have to wrap it to make it more pleasant to deal with (namespaces)2. it supports all of xpath, and you can even get xpath with regexes working. (elementtree api is not my friend) Infact, here is an lxml wrapper i've been using*** - it also has a beautifulsoup compatibility method too: http://secretvolcanobase.org/~tef/lxml/ *** A very cut down version - I actually use a slightly different api, and a lot more html processing shortcuts (like extracting form values) tef fucked around with this message at 12:10 on Nov 27, 2008 |
# ? Nov 27, 2008 10:10 |
|
Edit: Nevermind, should've Googled it to begin with, found a solution. Cyne fucked around with this message at 04:45 on Nov 28, 2008 |
# ? Nov 27, 2008 15:58 |
|
tef posted:(elementtree api is not my friend) Which parts don't you like? I ask because I've *coff* wrapped elementtree myself to compensate for some deficiencies.
|
# ? Nov 27, 2008 18:16 |
|
outlier posted:Which parts don't you like? I ask because I've *coff* wrapped elementtree myself to compensate for some deficiencies. Hard to inherit from or extend without composition, and having to handle the namespaces by hand. For example: At work, we get it to throw exceptions when an xpath doesn't match - dieing early has helped us find a number of issues in the screen scrapers.
|
# ? Nov 27, 2008 18:21 |
|
Edit: Dumb mistake
Juomes fucked around with this message at 05:43 on Nov 28, 2008 |
# ? Nov 28, 2008 03:38 |
|
I've started running into unicode errors while sending data around http calls and my database (charset in utf-8 for the server, db and tables).code:
Then there's this: code:
But then: code:
I googled around a bit and most of it seem to be about unicode vs byte strings. However, explanations have been a bit scarce, so I figure I may be seeing the whole thing wrong. How is unicode string conversion supposed to work? Maybe I'm tired, but I see no consistency in how different modules and the language itself seem to implement this.
|
# ? Nov 28, 2008 06:53 |
|
Is there any reason you need unicode objects to begin with? If you keep your data UTF-8-encoded to begin with you shouldn't have any problems. If a library is giving you unicode objects, you should encode them before passing them off to other libraries that aren't Unicode-aware. The reason unicode('éédaë') doesn't work is because Python is trying to decode your UTF-8 string as ASCII. In general, you should use str.decode() and unicode.encode() to convert between the two types.
|
# ? Nov 28, 2008 07:02 |
|
MononcQc posted:I googled around a bit and most of it seem to be about unicode vs byte strings. However, explanations have been a bit scarce, so I figure I may be seeing the whole thing wrong. Some libraries just flat out don't support unicode. Usually it's mentioned in the documentation. urlencode, though, is a binary encoding. Expecting it to work on unicode strings makes as much sense as expecting encoding a unicode string to base64 to work. There is no standardized encoding for urlencoding non-ASCII strings, though most people use utf-8. Python 2.x does some implicit coercion between str and unicode, but (fortunately) 3.x won't even try. Using ASCII as the default encoding for this coercion is the most sensible way to do it, because most unicode encodings use the lower seven bits the same way.
|
# ? Nov 28, 2008 10:05 |
|
I'm interested it learning how to use python to search for and download movie info from places like imdb.com and allmovie.com. Where's the best place to go to start learning?
|
# ? Nov 29, 2008 03:03 |
|
Phew, what a lot of great responses. I have to spend more time around Python people.
|
# ? Nov 29, 2008 03:31 |
|
chemosh6969 posted:I'm interested it learning how to use python to search for and download movie info from places like imdb.com and allmovie.com. I know you mean using Python to collect the information, but http://www.imdb.com/interfaces#plain It's free for personal use, but you have to work it out with them if you want to use it on a web site. I assume that means a lot of money. As far as using Python google "python screen scraping"
|
# ? Nov 29, 2008 03:38 |
|
So... This may go in the Mac thread but, it's a Python specific problem I just got a new Mac and when I enter into the Python shell I can't use the Up/Down/Left/Right arrows. For example... This is what happens when i push the up button code:
code:
Help me!
|
# ? Nov 29, 2008 04:15 |
|
I don't know anything about macs, but it looks like you don't have libreadline installed.
|
# ? Nov 29, 2008 04:22 |
|
Are you using Apple's distribution of Python 2.5? It should load readline by default, which provides key bindings. On a slightly unrelated note, I just discovered that the readline library in Apple's 2.5 distribution is actually a wrapper around libedit, and the bind syntax is completely different. To turn on completion you have to do readline.parse_and_bind('bind ^I rl_complete') instead of using 'tab: complete'. I can't believe I never knew this.
|
# ? Nov 29, 2008 05:50 |
|
chemosh6969 posted:I'm interested it learning how to use python to search for and download movie info from places like imdb.com and allmovie.com. python Screenscraper reporting in Downloading stuff from internet: urllib2 is pretty good, but pycurl is a little bit more featured (but more awkward to use). I would use the former first unless you *really* need transparent gzip decompression or https proxy support. Parsing html: BeautifulSoup does the job, but it is slow and it doesn't like XML all that well either. ElementTree can do XML parsing, but I personally find the api clunky but usable. Don't use regexes. lxml uses the element tree api, supports xpath over html and xml. it's quite a nice package with a cruddy api. if you know xpath already use lxml, it's good enough - otherwise use beautiful soup.
|
# ? Nov 29, 2008 12:23 |
|
I've gotten as much out of the way as possible with unicode, and most stuff now works, but I've ran in another problem: My database is currently having unicode as its charset and seems everything is stored fine when I access it via the command line, directly output its content to the browser or browse it with phpmyadmin. However, I need to pass the results through a module which seems to perform a conversion from str to unicode. the problem I've spotted is now this: for the string 'NOËL', I get: <type 'str' > NO\xcBL the problem is that it should be 'NO\xc3\x8bL' for a str type. 'NO\xcBL' is the unicode encoding. So apparently, I get an unicode encoded string under the format str. When the lib tries to re-encode it to unicode, the errors mentioned in my last post pop up. I'm currently using mysqldb to do my queries and it seems to always return 'str' strings. Is there anything I can do to fix that encoding problem then? Could it be a locale problem?
|
# ? Nov 29, 2008 17:20 |
|
Unicode isn't an encoding, it's a more general standard that specifies many different encodings, character sets, collations, etc. Your database is returning a latin-1-encoded string, not a UTF-8 string. You should check to see if your database's charset is set to UTF-8, and that you're instantiating your MySQLdb connection with charset='utf-8' and use_unicode=True as part of the arguments (to MySQLdb.connect()).
|
# ? Nov 29, 2008 18:30 |
|
This is more an appengine question, but does anyone know how I can parse XML in Google Appengine? I'm not 100% sure my problem below is an appengine issue or a Python + AppEngine on windows issue? I've googled and can't find any consistent help. Here is my code so far: code:
code:
|
# ? Nov 29, 2008 23:06 |
|
|
# ? May 14, 2024 05:24 |
|
I'm guessing xml.dom isn't installed or it's not on the path, since it's giving an import error.
|
# ? Nov 30, 2008 00:51 |