|
outlier posted:OSX10.5, Python 2.5.2. code:
|
# ? Jun 17, 2009 23:12 |
|
|
# ? May 11, 2024 07:07 |
|
pankus posted:Does anyone have some experience with numpy? I'm trying to copy a 2-dimensional array into a third dimension. I was wondering if there was a more efficient way to do what I am currently doing: code:
Avenging Dentist fucked around with this message at 00:51 on Jun 18, 2009 |
# ? Jun 18, 2009 00:36 |
|
Avenging Dentist posted:
tripwire fucked around with this message at 00:58 on Jun 18, 2009 |
# ? Jun 18, 2009 00:56 |
|
tripwire posted:Wow, I never knew about this... I wonder how it compares in performance? For the data used by the guy asking the question, it doesn't matter (seriously 6x5x25 is nothing). For larger datasets, you could get theoretically double the speed since the old-n-busted way allocates twice as much memory (one for each member of the Python list and then again for the new array).
|
# ? Jun 18, 2009 00:58 |
|
The reason I ask is because that operation runs about 20k times and was taking up 50% of my codes run time. It will eventually be expanded to 220x10x25, which I guess is still pretty small. Thanks for the help, I'll try it out tomorrow.
|
# ? Jun 18, 2009 02:09 |
Silly problem: I have, in main.py, the following class: code:
In another file, otherFile.py: code:
|
|
# ? Jun 18, 2009 04:58 |
|
If you want a static method like you're using, prefix the definition with the @staticmethod decorator.
|
# ? Jun 18, 2009 05:00 |
|
I've just started with Python a few days ago, so can anyone take a look at my code and see if my code's alright? The reason I ask is when I wrote my first Python program I was criticized for writing it too "c-style" and not using the features Python had to offer, so I want to know I'm doing everything efficiently. It's not that big, really. http://pastebin.com/m790e96f4 e: for reference, IRC sends messages like so: :origin COMMAND (maybe optional parameters) :text So if there's an easier way to parse them... Pie Colony fucked around with this message at 05:19 on Jun 18, 2009 |
# ? Jun 18, 2009 05:15 |
Avenging Dentist posted:If you want a static method like you're using, prefix the definition with the @staticmethod decorator. Exactly what I'm looking for. Thank you so much.
|
|
# ? Jun 18, 2009 05:16 |
|
Pie Colony posted:http://pastebin.com/m790e96f4 You could replace the whole loop in your recv_msg function with str.split. (Or splitlines if you don't mind playing fast and loose with line terminators.)
|
# ? Jun 18, 2009 05:33 |
|
Avenging Dentist posted:You could replace the whole loop in your recv_msg function with str.split. (Or splitlines if you don't mind playing fast and loose with line terminators.) I originally used str.split, but I ran into a little problem. Suppose I used '\r\n' as the delimiter, which is what all lines end with. If I had a packet like :server CMD :dothis\r\n :server CMD :dothat\r\n :serv as a packet, and I split it, I don't know how I can verify if that last command (which didn't get transferred entirely through this particular packet) was complete or not.
|
# ? Jun 18, 2009 05:38 |
|
Pie Colony posted:I don't know how I can verify if that last command (which didn't get transferred entirely through this particular packet) was complete or not. code:
|
# ? Jun 18, 2009 05:41 |
|
I've never made an irc client before, but wouldn't you want to avoid any while loops that don't use time.sleep? Unless you want to absolutely hammer any server you are attempting to connect to I guess. Python is known for having short and sweet idioms for many things that require cumbersome boilerplate code in c or java. Whenever you catch yourself righting a c style (initialization, loop test, increment) loop you should try to think of how you can take advantage of python's for each loop. Builtin functions like zip and split are both useful helper functions, and you can use them with map and filter to get a lot done with one statement. Also try to take advantage of list comprehensions or generator statements as well. They have a few subtle differences but for many applications, which style you use is up to you. Certain people find certain things easier using list comprehensions, others might prefer to build up lists manually with while loops. If you just want to do a loop for X iterations, use "for index in xrange(X):". My advice is try to keep things under 80 columns, because it makes it easier to read. You don't have to put brackets around a bunch of terms when assigning tuples, but it doesn't hurt. However, you can take advantage of list brackets and tuple parentheses to break up long statements on multiple lines. I do this because it makes it easier to read. I went through your code and tried to change things to be closer to how I might have done it. code:
tripwire fucked around with this message at 06:44 on Jun 18, 2009 |
# ? Jun 18, 2009 06:24 |
|
This might be slightly off topic, but since it's for Python I figure it'd be OK. I want to set up a virtual Linux installation on this Windows PC so I can play around with pycurses development. I want it to have the necessary installations for Python stuff, but not be bogged down by anything else. Does anyone else do this, and what distro would you recommend?
|
# ? Jun 18, 2009 11:45 |
|
CentOS has a server distribution that fits on a single CD. It doesn't include x windows so you should probably be comfortable with the command line before you download it.
|
# ? Jun 18, 2009 11:49 |
|
Centipeed posted:This might be slightly off topic, but since it's for Python I figure it'd be OK. I want to set up a virtual Linux installation on this Windows PC so I can play around with pycurses development. I want it to have the necessary installations for Python stuff, but not be bogged down by anything else. andLinux? you can run it within windows and it plays reasonably nicely
|
# ? Jun 18, 2009 13:39 |
|
I've never messed with programming something that access a network and I wanted to try something like that out. All I really want to do is automatically fill in forms. However, I would like to have my program automatically log in to the site that these forms are on. I've found a couple promising modules, such as Mechanize or twill, but I'm wondering if these are functionally equivalent or serve different purposes. Also, what do I need to know about security issues? Will these essentially use the server's SSL or other security measures during login or is it possible to open yourself to a giant security vulnerability if you don't know what your doing when your program sends such data as login info to a website?
|
# ? Jun 18, 2009 14:41 |
|
There are always things like coscripter as well, http://coscripter.research.ibm.com/coscripter/browse/ on the whole scraping is awful and I would avoid it.
|
# ? Jun 18, 2009 14:44 |
|
Pie Colony posted:I originally used str.split, but I ran into a little problem. Suppose I used '\r\n' as the delimiter, which is what all lines end with. code:
code:
|
# ? Jun 19, 2009 01:43 |
|
tef posted:andLinux? you can run it within windows and it plays reasonably nicely 32bit only though.
|
# ? Jun 19, 2009 03:38 |
Any guesses why this is happening?code:
pre:Main: Time delta: 47 -- Now: 7759 Player: Time delta in update: 0 Guard: Time delta in update: 0 Main: Time delta: 21 -- Now: 7780 Player: Time delta in update: 0 Guard: Time delta in update: 0 Main: Time delta: 18 -- Now: 7798 Player: Time delta in update: 0 Guard: Time delta in update: 0 Main: Time delta: 43 -- Now: 7841 code:
pre:Clock is null. Clock is null. 28 Clock is null. Clock is null. 23 Clock is null. Clock is null. 42 Clock is null. Clock is null. 30 Clock is null. Clock is null. EDIT again: Solution found: http://forums.somethingawful.com/showthread.php?threadid=3145796&userid=0&perpage=40&pagenumber=8#post362263110 Jo fucked around with this message at 05:49 on Jun 20, 2009 |
|
# ? Jun 20, 2009 00:26 |
|
I have a bit of a stupid question but please bare with me as I am python newb... How does one save a value from a generator object? I am using twill to access a webpage and view all the forms on it, these forms are viewed by twill as a generator object. What I need to be able to do though is save some of the data from the forms to a spreadsheet, and to make some decisions based on other elements. Any advice?
|
# ? Jun 20, 2009 01:07 |
|
Have you tried appending your values to a list? That's the general way to save values.
|
# ? Jun 20, 2009 01:26 |
|
Will that append the values individually or will it just be one big element in a list?
|
# ? Jun 20, 2009 01:30 |
|
That depends on how you do it. I would suggest trying it and then coming back if you have problems. Here's some documentation if you need it.
|
# ? Jun 20, 2009 01:36 |
|
hlfrk414 posted:That depends on how you do it. I would suggest trying it and then coming back if you have problems. Here's some documentation if you need it.
|
# ? Jun 20, 2009 01:40 |
|
eighty8 posted:I have a bit of a stupid question but please bare with me as I am python newb... I presume you're using twill.commands.showforms(). Just call list() on the return value. I don't know why Titus used a generator there, just makes things harder to inspect. In twill trunk, and in the never-actually-going-to-be-released 0.9.2 release, showforms and some other similar function will return lists instead.
|
# ? Jun 20, 2009 17:11 |
|
I need to write an app that will interact over a network with a MySQL database. Problem is, I don't really know much about MySQL or how to use it. I've found a few Python modules for MySQL, but I have so little background in this sort of thing that I don't really know where to start. For example, can an app directly query a database over a network, or do I need to send requests to a second, serverside Python script that'll query the database and send the results back over the network? If anyone can at least point me in the right direction, I'd be very grateful.
|
# ? Jun 20, 2009 19:42 |
|
BeefofAges posted:I need to write an app that will interact over a network with a MySQL database. Problem is, I don't really know much about MySQL or how to use it. I've found a few Python modules for MySQL, but I have so little background in this sort of thing that I don't really know where to start. For example, can an app directly query a database over a network, or do I need to send requests to a second, serverside Python script that'll query the database and send the results back over the network? Use MySQLdb, let the server listen on a public network address, and then set up a user account that will accept connections from wherever the Python app is. Here's a good tutorial for connecting to MySQL from Python.
|
# ? Jun 20, 2009 19:55 |
|
Janin posted:Use MySQLdb, let the server listen on a public network address, and then set up a user account that will accept connections from wherever the Python app is. Here's a good tutorial for connecting to MySQL from Python. This is great, thank you.
|
# ? Jun 20, 2009 20:53 |
|
Does anyone here happen to have experience with the mechanize module? I'm finding the documentation to be a little lacking, which wouldn't be terrible in and of itself, but I also can't seem to find active discussion about it anywhere on the internet. Two questions for now (though more may follow!): Is there a way to retrieve the cookies stored in an instance of Browser(), either individually or as a cookiejar? How can one effectively use the select_form() method if the forms on a given page do not have 'name' attributes? I assume the 'predicate' argument plays a role, here, but I can't find a clear explanation of how it works or what it is or how to use it. Aeolius fucked around with this message at 07:22 on Jun 21, 2009 |
# ? Jun 21, 2009 07:16 |
|
Actually I'd strongly recomend not letting your mysql listen on a public port. Some dudes gunna scan it down and brutalize it. If you must, set up some sort of SSH tunnel or something. Or better still just put the server on the same box as the machine and only accept local connections.
|
# ? Jun 21, 2009 10:21 |
|
duck monster posted:Actually I'd strongly recomend not letting your mysql listen on a public port. Some dudes gunna scan it down and brutalize it. This is all going to be on an internal network. It won't be accessible on the internet. It needs to be networked because this app is going to run on several hundred machines, all talking to one database.
|
# ? Jun 21, 2009 11:04 |
|
Quick question: I'm on windows xp using python 2.5.1 and when I do an 'os.path.sep' it returns "\\". How do I fix this?
|
# ? Jun 21, 2009 12:42 |
|
That's normal behavior. In order for \ to be interpreted as an actual character instead of an escape sequence, it has to be escaped with, well, \. When you're doing Windows paths in Python, they always look like "C:\\blah\\blah", or you can prefix your string literals with r, then \ isn't treated as an escape sequence, so you can also do r"C:\blah\blah"
|
# ? Jun 21, 2009 13:18 |
|
Thanks. That makes sense. I was stupid and tried to just concatenate '\' to my path and realized that it's the character for line break in python.
Crazak P fucked around with this message at 13:30 on Jun 21, 2009 |
# ? Jun 21, 2009 13:25 |
|
Im starting to fill with hate and despair about the lovely state of python on the mac compared with linux and windows (where module installation generally 'just works') anyone got any idea how the gently caress to get igraph to install. loving things got me flumoxed. Theres an installer for it on the site, but I think it just goes off and has a beer instead of installing anything
|
# ? Jun 21, 2009 13:32 |
|
duck monster posted:Im starting to fill with hate and despair about the lovely state of python on the mac compared with linux and windows (where module installation generally 'just works') poo poo works for me fine on my mac; I have no problems compiling stuff. I don't know about igraph - I looked at it, and the installers seems to be against the system installer, and not the framework builds python.org ships - however it is only python 2.5. Are you using the system python?
|
# ? Jun 21, 2009 14:25 |
|
I think so. Python 2.5 (r25:51918, Sep 19 2006, 08:49:13) [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin Type "help", "copyright", "credits" or "license" for more information.
|
# ? Jun 21, 2009 14:38 |
|
|
# ? May 11, 2024 07:07 |
|
duck monster posted:I think so. You should see this: Python 2.5.1 (r251:54863, Nov 12 2008, 17:08:51) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> Are you not on leopard?
|
# ? Jun 21, 2009 17:23 |