|
Jam2 posted:In what sort of environment do you guys code Python? I've been juggling notepad++ and the Python shell, pasting code across and evaluating it to see when it breaks. Is there a better way? I watched a Google lecture on Python. The speaker utilized Terminal and executed Python in that way. How would I do this in Windows? Should I work in OS X? My editor of choice is currently PyCharm, but for smaller projects I usually switch between a python command line and notepad++. Note that you don't have to copy-paste code, generally - just open the python command line from wherever your script is and you can do "import myscript" from within the python shell. You can then do "reload(myscript)" if you make changes and don't want to restart the whole shell. If you want to do this, make sure that the "normal functionality" of your script is wrapped in a block that looks like this: code:
Jam2 posted:How do I import a text file and go about parsing the contents? Do I need to import modules to do this? I want to be able to locate certain patterns of data, create lists, strings, and assign values to variables. code:
Jam2 posted:I've been using Python 3. Is this a bad idea? Should I stick with a version that's been in production for a while? The Facebook puzzle robot accepts Python 2.5.2. A visit to the Python 2.5.2 page informs that this version has been replaced by 2.5.5. What is a newbie to do?
|
# ? Dec 20, 2010 02:01 |
|
|
# ? Jun 13, 2024 03:59 |
|
the reason Facebook is on Python 2.5.2 is possibly because it's backended by Jython or Google App Engine VVV if the only reason people keep saying is 'too hard to update everything' or (even better) 'they're too lazy to update', then that's an incomplete picture. Even gigantic infrastructures requiring 2.5.x wouldn't necessarily by stuck on 2.5.2 forever. And the exact kind of organizational behemoth that mandates software package versions would also mandate installing security updates as soon as possible. Jython and App Engine just happen to be on 2.5.2 Lurchington fucked around with this message at 15:48 on Dec 20, 2010 |
# ? Dec 20, 2010 02:11 |
|
Lurchington posted:the reason Facebook is on Python 2.5.2 is possibly because it's backended by Jython or Google App Engine No. It's because upgrading a large amount of infrasture is a lot of work.
|
# ? Dec 20, 2010 04:24 |
|
Jam2 posted:In what sort of environment do you guys code Python? I've been juggling notepad++ and the Python shell, pasting code across and evaluating it to see when it breaks. Is there a better way? I watched a Google lecture on Python. The speaker utilized Terminal and executed Python in that way. How would I do this in Windows? Should I work in OS X? I use python in both Linux and Windows at work and use emacs with python-mode in both environments. The learning curve is a little steep if you're used to standard windows/mac text editors but not daunting. It's awesome to actually having the python interpreter running the same window that you're editing in. You can easily highlight a chunk of code and execute it with a keystroke combo, and there are lots of other useful keystroke commands for controlling indentation and similar things.
|
# ? Dec 20, 2010 05:26 |
|
Cross-posting this with the Django thread: I'm trying to dynamically load a class from a specific module (called 'commands') and the code runs totally cool on my local setup running from a local Django server. This bombs out though when I deploy to Google App Engine. I've tried adding the commands module's parent module to the __import__ as well with no avail (on either setup in that case). Here's the code: code:
Edit: and the clarify, it doesn't bomb out on the commands module. If I have a command like 'commands.cat' it can't find 'cat'. Ferg fucked around with this message at 17:50 on Dec 20, 2010 |
# ? Dec 20, 2010 17:46 |
|
Ferg posted:Cross-posting this with the Django thread: GAE runs a restricted version of 2.5.whatever. For instance, the apply() built-in does not wok in GAR, yet that builtin is included in the ame version of python that GAE claims to run. It's possible that the __import__ trick you're doing is not supported in GAE's cusom implementation.
|
# ? Dec 21, 2010 02:41 |
|
nbv4 posted:GAE runs a restricted version of 2.5.whatever. For instance, the apply() built-in does not wok in GAR, yet that builtin is included in the ame version of python that GAE claims to run. It's possible that the __import__ trick you're doing is not supported in GAE's cusom implementation. WTF apply() doesn't work? apply is literally lambda f, *args, **kwargs: f(*args, **kwargs). In any even __import__ works, when used correctly, since Django works.
|
# ? Dec 21, 2010 04:40 |
|
king_kilr posted:WTF apply() doesn't work? apply is literally lambda f, *args, **kwargs: f(*args, **kwargs). In any even __import__ works, when used correctly, since Django works. Yeah given that this is such a huge feature of Django, it has to work in some fashion. Figured it might be a 2.6/2.5 discrepancy though.
|
# ? Dec 21, 2010 06:41 |
|
Distutils is really making my head hurt. Has anyone ever wrote and built c extension modules for a python project on windows? I tried installing the free version of visual studio last night and was getting nowhere trying to build this package: http://code.google.com/p/neat-python/ There are 3 modules in there which have C++ implementations, and the setup.py looks like this: code:
Then, I get this: http://pastebin.com/6KhTWRpJ I'm getting link errors because (and someone correct me if I'm wrong), it seems like distutils is trying to guess the names of some initialization functions by just taking the extension name and prefixing it with "init"; that may be fine for top level modules, but since these extensions sit inside a package hierarchy its passing visual studio this argument "/EXPORT initneat/ifnn/ifnn_cpp" when (I'm assuming) it should be "/EXPORT neat/ifnn/initifnn_cpp". So, unsure of whether theres a mistake in setup.py or in distutils, I tried hacking distutils again to just export the exact name of that "init" function in the c++ source for each extension module rather than just slapping init in front of the whole name. After doing that, I would still get a link error thrown by visual studio, but after trying 3 times in a row it presumably compiled the libraries it was complaining it didn't have and then successfully linked them. Only when I try importing these compiled modules now, I end up with a very helpful traceback: code:
|
# ? Dec 21, 2010 22:18 |
|
Using syslog is it possible to log to a file other than /var/log/messages or /var/log/syslog? I want my program to have it's own file
|
# ? Dec 21, 2010 23:07 |
|
Yakattak posted:Using syslog is it possible to log to a file other than /var/log/messages or /var/log/syslog? I want my program to have it's own file http://docs.python.org/library/logging.html
|
# ? Dec 22, 2010 00:29 |
|
MaberMK posted:http://docs.python.org/library/logging.html Ah poo poo that looks way better, thanks.
|
# ? Dec 22, 2010 00:46 |
|
using a syslog logging handler is usually the way you need to go for any multiprocessing tasks you're doing. Logging to a file from multiple processes means errors opening the file for reading/writing
|
# ? Dec 22, 2010 16:02 |
|
Lurchington posted:using a syslog logging handler is usually the way you need to go for any multiprocessing tasks you're doing. Logging to a file from multiple processes means errors opening the file for reading/writing Not to mention a shitload of latency introduced from all that work the logging module has to do. Logging to file aside, the logging module has lots of other problems: If you have lots of uses of the function "trace" or "info", you pay for each time a string is built and passed into those functions and for the function call itself, regardless of whether the logging level would have blackholed the message anyway. Having to call the trace() function a lot in a tight loop might not be a big deal in java where function calls are comparatively cheap, but in python that can absolutely slay your performance. So much so, that you get people pining for c preprocessor macros so they can alleviate the pain: http://dound.com/2010/02/python-logging-performance/http://dound.com/2010/02/python-logging-performance/ http://cogidev.blogspot.com/2010/02/python-tracing-performance.html tripwire fucked around with this message at 22:02 on Dec 22, 2010 |
# ? Dec 22, 2010 21:58 |
|
I actually meant logging.handlers.SysLogHandler versus a FileHandler, but you bring up some excellent points on why it might be good to use the syslog module
|
# ? Dec 22, 2010 22:41 |
|
Is there a way to configure logging (using a config file) to log errors+ to stdout and anything below that to a file?
|
# ? Dec 22, 2010 22:53 |
|
Something like this (untested):code:
|
# ? Dec 23, 2010 00:53 |
|
king_kilr posted:WTF apply() doesn't work? apply is literally lambda f, *args, **kwargs: f(*args, **kwargs). In any even __import__ works, when used correctly, since Django works. sorry i meant buffer()
|
# ? Dec 23, 2010 02:17 |
|
code:
quote:Let’s trace this function using this list: Python hobbyist/newbie here. Can someone please explain to me why that works? How is he using lprod(l) as a value inside the function definition of it?
|
# ? Dec 24, 2010 03:34 |
|
Swanson Broth posted:
Whenever lprod is called, it then calls itself with a list with one fewer element than it started with. Until it's called with an empty list, which ends the series of calls and returns an integer. The first time lprod([2,2,3,1]) is called, it returns 1 * lprod([2,2,3]), which is just lprod([2,2,3]). Continuing: lprod([2,2,3]) = 3 * lprod([2,2]) lprod([2,2]) = 2 * lprod([2]) lprod([2]) = 2 * lprod([]) lprod([]) = 1 So, working backwards, we have 1 * 2 * 2 * 3, or 12. It's called recursion, if you want to read more about it.
|
# ? Dec 24, 2010 03:59 |
|
Swanson Broth posted:
That's a really bad way of implementing that, actually. Lists are mutable, which means that they are passed by reference and can be modified. So every time this thing calls itself to multiply the next number, it literally removes a value from the list you passed it. As in, it modifies what the caller passed, e.g.: code:
code:
code:
code:
|
# ? Dec 24, 2010 06:10 |
|
I have this 3rd party ircbot/markov chain program thing written in Python and it's really thrashing the hard drive every time it generates replies to user messages. I have looked through the source code and can't figure out whats really causing it since it appears to me that the bot simply loads the database files into memory completely, marshall.loads() the huge string objects into dictionary objects and then goes on to do whatever with the dictionary objects. How should I proceed with trying to find out what is causing all this disk activity? Just pointing me at the right module/software would suffice I think.
|
# ? Dec 24, 2010 10:47 |
|
Well, are the database files so large that your computer is swapping them out to disk then thrashing on access? If there's a significant number of items it's loading, that application might be just not built to handle large datasets efficiently. I mean, that sounds like a poor way for that program to operate. Something like sqlite would be a much better solution. It's pretty much built to do searching and indexing of on-disk objects efficiently. Are these databases static or are they the input that you're providing? ErIog fucked around with this message at 15:40 on Dec 24, 2010 |
# ? Dec 24, 2010 15:33 |
|
Can someone tell me why is variable a considered higher than variable b?? I have a very simple program meant to tell which variable is the maximum. here's the code code:
|
# ? Dec 25, 2010 01:29 |
|
234 > 1234 is false "234" > "1234" is true you need printMax(int(a), int(b))
|
# ? Dec 25, 2010 01:34 |
|
Janin posted:234 > 1234 is false I just tried it right now and I got this The syntax is wrong, but I get that I have to make it an integer somehow. bc87 fucked around with this message at 01:42 on Dec 25, 2010 |
# ? Dec 25, 2010 01:40 |
|
bc87 posted:I just tried it right now and I got this don't use int in the def for printMax. Use it when you call printMax.
|
# ? Dec 25, 2010 01:41 |
|
Thermopyle posted:don't use int in the def for printMax. Thanks, I got it working now. I'm learning python, and new to programming, that's why I don't get this poo poo at first.
|
# ? Dec 25, 2010 01:45 |
|
bc87 posted:Thanks, I got it working now. I'm learning python, and new to programming, that's why I don't get this poo poo at first. It's cool, you'll get it eventually. (you can say poo poo by the way)
|
# ? Dec 25, 2010 01:52 |
|
For the function open() is there a way to specify the directory it will look into? i dont want to type in the whole address into the function.
awesomepanda fucked around with this message at 23:15 on Dec 26, 2010 |
# ? Dec 26, 2010 23:11 |
|
CrazyPanda posted:For the function open() is there a way to specify the directory it will look into? i dont want to type in the whole address into the function. You can use os.chdir
|
# ? Dec 26, 2010 23:19 |
|
CrazyPanda posted:For the function open() is there a way to specify the directory it will look into? i dont want to type in the whole address into the function. You're using a programming language. Variables are your friend. Not knowing exactly what your question means...try this... code:
|
# ? Dec 26, 2010 23:20 |
|
Hi thanks Thermopyle and No Safe Word. What directory does open() look into when opening the file?
|
# ? Dec 26, 2010 23:25 |
|
CrazyPanda posted:Hi thanks Thermopyle and No Safe Word. The current working directory, which you can get via os.getcwd and change via os.chdir as I mentioned
|
# ? Dec 26, 2010 23:29 |
|
No Safe Word posted:The current working directory, which you can get via os.getcwd and change via os.chdir as I mentioned Thank you so very much!
|
# ? Dec 26, 2010 23:34 |
|
Kind of new to python... what would I want to use if I have an HTML document I wanna grab table data from? Is there an easy way via some pre-made method or will I have to get my hands dirty and regex?
|
# ? Dec 27, 2010 00:15 |
|
GregNorc posted:Kind of new to python... what would I want to use if I have an HTML document I wanna grab table data from? Is there an easy way via some pre-made method or will I have to get my hands dirty and regex? Ugh. Don't use regex to parse HTML. Ever. lxml is your friend. http://codespeak.net/lxml/ http://codespeak.net/lxml/parsing.html
|
# ? Dec 27, 2010 00:35 |
|
PyQuery! http://pypi.python.org/pypi/pyquery
|
# ? Dec 27, 2010 00:37 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:23 on Mar 13, 2017 |
# ? Dec 27, 2010 01:51 |
|
|
# ? Jun 13, 2024 03:59 |
|
GregNorc posted:I guess I should clarify that I'm not looking to do anything with said html, just strip out the data in a column in a table... Both of the suggestions provided are good for that.
|
# ? Dec 27, 2010 01:53 |