|
Jaur posted:Is it something wrong with IDLE, my drivers, my code? It's IDLE. It doesn't play well with pygame if you don't call pygame.quit() at the end. See the pygame wiki entry for more (and ignore the spam).
|
# ? Oct 19, 2011 21:15 |
|
|
# ? May 20, 2024 05:23 |
|
Haystack posted:Check out Supervisor for a pre-rolled solution. Looks great. Thanks!
|
# ? Oct 19, 2011 22:01 |
|
GregNorc posted:Let's say I have a list of five integers. For sake of simplicity, l = [1,2,3,4,5] This is too late but I would have iterated from 0 to 31 (inclusive), grabbed the binary representation of each integer, and used that to pick elements from the list.
|
# ? Oct 20, 2011 05:58 |
|
I just discovered that this is valid in Python 3:code:
code:
But the only information I can find about it is the diff that introduced it. Apparently the test expressions are evaluated when the function is defined: code:
Scaevolus fucked around with this message at 18:58 on Oct 20, 2011 |
# ? Oct 20, 2011 18:55 |
|
Scaevolus posted:I just discovered that this is valid in Python 3: Those look like the type annotations in PEP 3107. As far as I know, the standard lib & interpreter do nothing with them, but you could build tools around that extra data.
|
# ? Oct 20, 2011 19:23 |
|
More explicitly,code:
|
# ? Oct 21, 2011 08:33 |
|
the likely use case for annotations (and for them being arbitrary functions) would be for your unittests to make assertions that it's bringing and returning expected types.code:
edit: I guess IDEs could make use of it as well Lurchington fucked around with this message at 19:17 on Oct 21, 2011 |
# ? Oct 21, 2011 19:15 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:24 on Mar 13, 2017 |
# ? Oct 21, 2011 22:50 |
|
How about [0] * 10? e: code:
|
# ? Oct 21, 2011 22:53 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:24 on Mar 13, 2017 |
# ? Oct 21, 2011 23:07 |
|
GregNorc posted:If I nest it, then it seems to only create one list, and reference everything else." That's a caveat of the [ expr ] * 5 syntax: expr is evaluated once and referenced in the other list entries: code:
code:
[ expr for captured variable name in sequence ] expr can be any valid python expression, although typically you would use the captured variable in the expression somewhere. In the example above though, I don't use the captured variable, so I stick with the convention of naming it _ (to indicate a dummy/meaningless variable). tripwire fucked around with this message at 23:34 on Oct 21, 2011 |
# ? Oct 21, 2011 23:29 |
|
Edit: doublepost
maskenfreiheit fucked around with this message at 01:25 on Mar 13, 2017 |
# ? Oct 21, 2011 23:37 |
|
GregNorc posted:Ok... I think I understand... The expr part above can be any valid python expression.. including just 0, or another list comprehension! Check this out: code:
|
# ? Oct 21, 2011 23:48 |
|
tripwire posted:
|
# ? Oct 22, 2011 00:18 |
|
TasteMyHouse posted:x[0][1] += 1
|
# ? Oct 22, 2011 00:19 |
|
e: Hey I should read threads
TasteMyHouse fucked around with this message at 00:26 on Oct 22, 2011 |
# ? Oct 22, 2011 00:22 |
|
GregNorc posted:Ok... I think I understand... you could just do code:
|
# ? Oct 22, 2011 03:21 |
|
Or you could docode:
Or, if you really need performance, I think numpy has explicit functions for ones() and zeroes() which do the same job.
|
# ? Oct 22, 2011 11:21 |
|
Still learning python. I'm working on a new project for converting Checkpoint firewall rulebases. I want to read the values from the rules and objects text files and store them in a data structure that looks like this in my head: code:
Is there a built-in data structure similar to dictionaries that would work for this? I've been reading a lot and I'm probably just not knowing the right stuff to google for to find it.
|
# ? Oct 24, 2011 18:45 |
|
fnordcircle posted:Still learning python. Unless I'm misunderstanding, I think you could just create a class with the sources, destinations, and ports as lists assigned to attributes or returned via methods. Something like: (not tested and just typed up here without much thought) code:
Thermopyle fucked around with this message at 18:57 on Oct 24, 2011 |
# ? Oct 24, 2011 18:54 |
|
Ok cool I'll read more about classes. I've sort of been taking the 'learn about what I need to learn right now' approach since I'm typically working on tight deadlines. Thanks man!
|
# ? Oct 24, 2011 19:26 |
|
fnordcircle posted:Ok cool I'll read more about classes. I've sort of been taking the 'learn about what I need to learn right now' approach since I'm typically working on tight deadlines. Remember, when you do OO, model the problem abstractly: Entities have states(variables) and messages ("Do this, little objects") aka methods, then implement them. Its amazingly powerful as long as you think of it this way.
|
# ? Oct 25, 2011 06:53 |
|
duck monster posted:Remember, when you do OO, model the problem abstractly: Entities have states(variables) and messages ("Do this, little objects") aka methods, then implement them. Its amazingly powerful as long as you think of it this way. I think I have a little ways to go to wrap my head around it all. Got one question, which I imagine will highlight how I'm not 'getting' classes yet. If I have a variable named netobj, how do I create a class instance whose name is the value of that variable? So if netobj = 'Block_Group', how can I use that to create a class named Block_Group?
|
# ? Oct 27, 2011 04:37 |
|
So I'm using gevent for the first time today and there's something I want to do but I'm dumb and can't figure it out even though it's probably trivial. Right now I just have a little script that spawns a number of greenlets that then sleep for a random amount of time. What I want to do is keep track of how many are still alive and how many are done. Like, kinda a progress bar thing. Here's a trivial example. How could I find out what percentage of them have completed at any given time? code:
|
# ? Oct 27, 2011 07:06 |
|
fnordcircle posted:I think I have a little ways to go to wrap my head around it all. Is this what you're asking about? code:
|
# ? Oct 27, 2011 07:45 |
|
pliable posted:I have no idea where to ask this, so I have chosen YOU, Game Development Megathread! Reposting this here to hopefully get more answers...
|
# ? Oct 27, 2011 08:32 |
|
I'm looking for a tutor who can teach me to solve basic mathematical assignments in Python (polynomials, differential equations, etc.) Your job would just be to answer sporadic questions on Skype to keep everything running smoothly. 12 bucks an hour. If you are interested, send a mail to fredrikvogler at gmail.
|
# ? Oct 27, 2011 10:00 |
|
FoiledAgain posted:Is this what you're asking about? Thanks! But I don't think I'm doing a good job explaining what I'm asking. I have a file with hundreds of network objects from a checkpoint firewall. They are in blocks like this: code:
Depending on the object type (network or group in this instance) I need to extract the name, IP, netmask and any group members (the two lines after :type (group) )and assign them to attributes of a class instance. Basically I need to build out a long data structure to store all of these values for each of these checkpoint network objects which I can then extract the data from later when I'm parsing the actual rulebase which references these checkpoint data values. I guess what I'm confused about is what the best way to do this is and how to do it on the fly. If I'm understanding correctly your code above just creates a class instance named netobj. I can manually create a new class instance, like you do with netobj above, but I need to do this dynamically for hundreds of checkpoint network objects.
|
# ? Oct 27, 2011 12:42 |
|
pliable posted:Reposting this here to hopefully get more answers... You might have to give us a little more than that. Are you running it from the command line? Is there any output at all? Are you using the stock version of Python that comes with OSX? fnordcircle posted:Thanks! But I don't think I'm doing a good job explaining what I'm asking. If you were more comfortable with Python (not a dig at you, everyone starts somewhere) I'd suggest PyParsing or something similar.
|
# ? Oct 27, 2011 13:10 |
|
Captain Capacitor posted:If you were more comfortable with Python (not a dig at you, everyone starts somewhere) I'd suggest PyParsing or something similar. Nah, not at all. At this point I've ditched the idea of objects for now since I clearly don't get it and I've got to get this done by the end of the day. For now I'm just going with a list with a line for each object appending all the data I need to that one line and starting the line with the checkpoint object name so I can fiddle with them later. Thanks!
|
# ? Oct 27, 2011 14:10 |
|
Captain Capacitor posted:You might have to give us a little more than that. Are you running it from the command line? Is there any output at all? Are you using the stock version of Python that comes with OSX? Yeah, sorry about that... Yes, attempting to run it from the command line, and I tried using both python and pythonw. This is the output I get with either: code:
|
# ? Oct 27, 2011 18:44 |
|
fnordcircle posted:Nah, not at all. At this point I've ditched the idea of objects for now since I clearly don't get it and I've got to get this done by the end of the day. Classes and objects are are possibly the most powerful paradigm in modern programming so don't dismiss them as some fringe feature. Unfortunately, in my opinion at least, classes are where the "Python is easy for beginners" mantra breaks down. For learning object oriented programming, a purely OO language like Java or C# tends to be much simpler. Objects and classes lose some of their purity when they're hedged into scripting languages like Python and Javascript, which is fine for experienced developers but not helpful when you're a new programmer trying to "get" classes and objects and inheritence.
|
# ? Oct 27, 2011 18:55 |
|
Eggnogium posted:Classes and objects are are possibly the most powerful paradigm in modern programming so don't dismiss them as some fringe feature. Unfortunately, in my opinion at least, classes are where the "Python is easy for beginners" mantra breaks down. For learning object oriented programming, a purely OO language like Java or C# tends to be much simpler. Objects and classes lose some of their purity when they're hedged into scripting languages like Python and Javascript, which is fine for experienced developers but not helpful when you're a new programmer trying to "get" classes and objects and inheritence. Not that we're in the wrong thread to discuss this (we are), but you may enjoy picking a fight over in this thread here: http://forums.somethingawful.com/showthread.php?threadid=3444008 For what it is worth I think teaching object orientation first causes brain damage.
|
# ? Oct 27, 2011 20:11 |
|
Eggnogium posted:Classes and objects are are possibly the most powerful paradigm in modern programming so don't dismiss them as some fringe feature. Unfortunately, in my opinion at least, classes are where the "Python is easy for beginners" mantra breaks down. For learning object oriented programming, a purely OO language like Java or C# tends to be much simpler. Objects and classes lose some of their purity when they're hedged into scripting languages like Python and Javascript, which is fine for experienced developers but not helpful when you're a new programmer trying to "get" classes and objects and inheritence. Oh no, definitely not. Basically we have a hundred conversions we have to do and everyone has been doing them by hand. Converting a Proventia-M firewall or Checkpoint to an ASA takes 2-4 days of an engineer's time. I have a hard-on for automation, which I typically accomplish with Autohotkey. So I get scheduled 4 days to do a firewall build and I've been 'stealing' a day or two of that time to build a python conversion script. So while I'd love to sit and learn classes the pressure of the clock ticking is kinda stressful so I have to go with what I know. Even if it means I'll spend 2 hours doing something I could probably do in 15 minutes if I understood the language better but it doesn't seem like I'll be able to learn something like classes in 2 hours. In the end I realized that just using dictionaries with specifically-formated data strings was much easier for me to accomplish now, but I thoroughly intend to get a better grasp of classes since I'd love to end up writing my own python roguelike-ish program sometime down the road. Thanks for the encouragment to look into classes!
|
# ? Oct 29, 2011 08:58 |
|
I'd like some input on this project I'm working on. Short blurb: A daemon receives emails from Postfix and decides if they should be sent from the server or piped through Amazon's SES service. Postfix pipes the email to a small client that uses a ZeroMQ (0MQ) queue to talk to the daemon. The daemon keeps stats, like how many emails sent locally, how many through SES, how many bounces received, etc. I would like to be able to query the stats at any time, so I also added a simple socket server that listens on a TCP port and outputs the stats to any connection. Now, since I'm already polling the ZMQ queue in a while True loop, I need to have another such loop for my TCP socket. My initial thought was to spawn a separate process for the stats TCP socket. That works well but passing objects between the main ZMQ loop process and the TCP loop process is annoying. Right now, I use multiprocessing.Manager to have a shared list between the two procs but it's not working with dictionaries and it gets even more annoying if I have to copy/modify lists between the two. So I started looking at having everything in the same process but to use nonblocking/zmq.NOBLOCK modes, a bit like this: code:
So maybe I'm just missing another way of doing this. I don't want to post the stats to a webapp or store them in a DB, I'd like a low-key way of telling the daemon, "Hey, where are you at?" If i use multiprocessing.Pipe[ between the two processes, each process would need to have a second loop on that pipe and that starts looking messy. Anybody got suggestions or ideas?
|
# ? Nov 1, 2011 10:51 |
|
have you thought about using threads?
|
# ? Nov 1, 2011 15:50 |
|
tef posted:have you thought about using threads? I never really used threads before, with the reputation of being more complex and hard to debug. I'll give threads a look tomorrow. Is sharing objects between threads much easier than with multiprocessing?
|
# ? Nov 1, 2011 16:28 |
|
Have you thought of using ZeroMQ's polling facilities? You can add multiple sockets to it and poll for any activity on them.
Captain Capacitor fucked around with this message at 16:50 on Nov 1, 2011 |
# ? Nov 1, 2011 16:48 |
|
Captain Capacitor posted:Have you thought of using ZeroMQ's polling facilities? You can add multiple sockets to it and poll for any activity on them. Yeah I did look at that, but ZeroMQ TCP sockets don't support telnet (or even netcat) so I'd need to write a small client that uses ZeroMQ's REQ/REP. Ideally, I'd like to avoid creating a specific client just to pool the stats, to eventually plug it into Nagios or Cacti, or just to allow non-python colleagues to quickly get stats. I found some kind of hack that mixes asyncore and zmq, haven't tried it yet but I'm not sure it even works.
|
# ? Nov 1, 2011 17:15 |
|
|
# ? May 20, 2024 05:23 |
|
Senso posted:Yeah I did look at that, but ZeroMQ TCP sockets don't support telnet (or even netcat) so I'd need to write a small client that uses ZeroMQ's REQ/REP. Ideally, I'd like to avoid creating a specific client just to pool the stats, to eventually plug it into Nagios or Cacti, or just to allow non-python colleagues to quickly get stats. I don't have time at the moment to think about your problem in detail, but I've done similar sorts of things with eventlet.
|
# ? Nov 1, 2011 17:17 |