|
keyframe posted:Another day another question You need to use raw_input instead of input. In Python 2.7, input causes the user's input to be eval'd, which you don't want. raw_input gives you back a string. Try separating the tasks of getting user input, validating user input, and appending to a list. Python code:
|
# ? Aug 27, 2013 18:46 |
|
|
# ? May 9, 2024 11:36 |
|
Simple question, but googling can't find me an answer. Can I use numpy.arange to make a 2-d array? I can't figure out how that's possible. Thanks.
|
# ? Aug 28, 2013 03:54 |
|
I've tried everything with this piece code as I did not want to have to ask. But I've been jacking with it for almost an hour and it's getting rather annoying.code:
I have checked all my spacing and everything has the correct spacing. Is there some small whitespace error I'm not seeing?
|
# ? Aug 28, 2013 03:57 |
|
Why do you indent at the for? Have you tried just moving everything back an indent and seeing if it works?
|
# ? Aug 28, 2013 03:58 |
|
What's the recommended python binary parsing library? Something like Data.Binary for Haskell is what I'd really like (declarative decoding/encoding)
|
# ? Aug 28, 2013 04:04 |
|
the posted:Why do you indent at the for? Have you tried just moving everything back an indent and seeing if it works? I thought you had to start all for loops with an indention.
|
# ? Aug 28, 2013 04:18 |
|
digitalcamo posted:I thought you had to start all for loops with an indention. I'm no expert, but I'm pretty sure you don't (as my own code I'm looking at right now doesn't have it): Python code:
|
# ? Aug 28, 2013 04:27 |
|
Malcolm XML posted:What's the recommended python binary parsing library? Something like Data.Binary for Haskell is what I'd really like (declarative decoding/encoding) Real-world formats are too messy to be entirely declarative. I'd just write custom code using struct.parse. Though I've heard some people talk about how awesome Construct is. It's just not good enough for my use case (which is admittedly insane)
|
# ? Aug 28, 2013 04:34 |
|
digitalcamo posted:I thought you had to start all for loops with an indention. Nope. An indented block of code generally means 'this block of code is executed within the logical context of the thing its indented under.' You only have to indent immediately after a statement that by it's nature encloses a block of code, such as is the case with for, if, while, and def statements. As a general rule of thumb, if a line ends with a colon, the next line should be indented. If not, you don't (and most often shouldn't) indent. A corrected version of your code looks like this: code:
|
# ? Aug 28, 2013 04:47 |
|
Suspicious Dish posted:Real-world formats are too messy to be entirely declarative. I'd just write custom code using struct.parse. I'll give that a look. What kind of stupid format are you using that Data.Binary/construct can't decode/encode?
|
# ? Aug 28, 2013 04:55 |
|
SWF. Don't ask.
|
# ? Aug 28, 2013 04:57 |
|
the posted:Simple question, but googling can't find me an answer. This is the first example in the official? Numpy tutorial.
|
# ? Aug 28, 2013 05:17 |
|
Dominoes posted:np.arange(15).reshape(3,5) Well, hm.. So, the command Python code:
|
# ? Aug 28, 2013 05:21 |
|
the posted:Well, hm.. np.arange(100).reshape(10,10) will you give you 0-99, in 2 axes split in increments of 10. Dominoes fucked around with this message at 05:31 on Aug 28, 2013 |
# ? Aug 28, 2013 05:28 |
|
Dominoes posted:0-9. What do you mean by in both dimensions? Write out a truncated example of what you're looking for. I'm trying to make a coordinate grid of points that go from 0 to 10 in both "x and y" dimensions. So I want a 2d array that has (0,0, (0,1), (1,0), (1,1), etc... thanks!
|
# ? Aug 28, 2013 05:31 |
|
Suspicious Dish posted:SWF. Don't ask. Why do you need to develop your own parser instead of using one that someone else already wrote? For example: https://github.com/timknip/pyswf
|
# ? Aug 28, 2013 06:30 |
|
the posted:I'm trying to make a coordinate grid of points that go from 0 to 10 in both "x and y" dimensions. So I want a 2d array that has (0,0, (0,1), (1,0), (1,1), etc... Try meshgrid.
|
# ? Aug 28, 2013 07:05 |
|
Haystack posted:
There is still an issue with variables in this code. (Although it will run and give the expected answer, thanks to Python's variable lookup rules.)
|
# ? Aug 28, 2013 08:49 |
|
the posted:I'm trying to make a coordinate grid of points that go from 0 to 10 in both "x and y" dimensions. So I want a 2d array that has (0,0, (0,1), (1,0), (1,1), etc... I still don't understand your request. It sounds like you want a 2D array of tuple coordinates or something. Is that what you want? I think that numpy only supports basic data types, so you wouldn't be able to use arange for something like this. If you want two 2D arrays, one with 0...10 in the X direction and one with 0...10 in the Y direction, then that's certainly feasible.
|
# ? Aug 28, 2013 09:39 |
|
Malcolm XML posted:What's the recommended python binary parsing library? Something like Data.Binary for Haskell is what I'd really like (declarative decoding/encoding) There isn't one. I don't know of any combinator parsers for python for binary data, and I would imagine they're horrifically slow on cpython. In the meantime, there is always pack/unpack http://docs.python.org/2/library/struct.html
|
# ? Aug 28, 2013 10:30 |
|
the posted:I'm trying to make a coordinate grid of points that go from 0 to 10 in both "x and y" dimensions. So I want a 2d array that has (0,0, (0,1), (1,0), (1,1), etc... Like Quarkjets said, you can't use tuples in numpy arrays. Dominoes fucked around with this message at 13:53 on Aug 28, 2013 |
# ? Aug 28, 2013 13:50 |
|
BeefofAges posted:Why do you need to develop your own parser instead of using one that someone else already wrote? Because I wrote it before that one (and any other Python one; I checked) existed: https://github.com/magcius/fusion
|
# ? Aug 28, 2013 15:11 |
|
Thanks for the help on the arrays, I was able to figure it out. Now, let's say I have a 10x10 array that has in each spot either a 0 or a 1. How would I go about plotting only the spots with 1, and in the coordinates that have a 1 in them? Like if array[5,3] has a 1, I'd put a dot at (5,3). I was thinking something like: Python code:
|
# ? Aug 28, 2013 16:42 |
|
the posted:Now, let's say I have a 10x10 array that has in each spot either a 0 or a 1. How would I go about plotting only the spots with 1, and in the coordinates that have a 1 in them? Like if array[5,3] has a 1, I'd put a dot at (5,3). You can use spy() from matplotlib.
|
# ? Aug 28, 2013 16:51 |
|
Nippashish posted:You can use spy() from matplotlib. Oh wow, That's friggin awesome! Thanks so much. the fucked around with this message at 17:26 on Aug 28, 2013 |
# ? Aug 28, 2013 16:51 |
|
Malcolm XML posted:What's the recommended python binary parsing library? Something like Data.Binary for Haskell is what I'd really like (declarative decoding/encoding) If it's your own data format you could use something like protobuf, which has first-tier support for Python.
|
# ? Aug 28, 2013 18:10 |
|
Suspicious Dish posted:Real-world formats are too messy to be entirely declarative. I'd just write custom code using struct.parse. When I've needed to parse binary data in python I've always rolled my own stuff with struct.pack/unpack that behaves a lot like Construct. I'll give Construct a shot next time. Is your SWF so crazy that you can't employ something like Construct for pieces of it?
|
# ? Aug 28, 2013 19:24 |
|
Alligator posted:proxies is supposed to be a dict mapping a protocol to a proxy. if they're http proxies it'll look like this (untested): I made some changes to this script and it seems like it should work but I'm still getting errors. Any ideas here? Only reason im printing the html is to give my self some sort of test output. Python code:
{"https": "https://61.155.159.9:8989"} {"http": "http://24.172.34.114:8181"} {"http": "http://87.236.210.45:443"}
|
# ? Aug 28, 2013 19:43 |
|
I'm trying to be all fancy and clever and make a one-liner that takescode:
code:
I came up with this: Python code:
Python code:
I know how to do it with a couple of regular loops, but I'm annoyed that I can't get it to work this way, too.
|
# ? Aug 28, 2013 19:50 |
|
Munkeymon posted:I came up with this: I take it you are aware that "for row in inpt" is the inner loop here? The result of that code will be that splat contains the "Product 1" line for each and every item in order, followed by the "Product 2" line for each and every item in order, etc. quote:
On the other hand, I do not understand how this code can be giving you the result you expect. I would expect it to give you "Product 1" for the first item, then "Product 2" for the second item, and so on until it runs out of product numbers. Also, use next(inpt) instead of inpt.next(), for future-proofing.
|
# ? Aug 28, 2013 20:48 |
|
madkapitolist posted:I made some changes to this script and it seems like it should work but I'm still getting errors. What errors?
|
# ? Aug 28, 2013 20:52 |
|
Hammerite posted:I take it you are aware that "for row in inpt" is the inner loop here? Welp, that's the problem - I got the order of evaluation mixed up. Probably why I don't use nested (or even conditional) comprehensions more often and a reason I should: I don't parse them correctly at first glance. In my defense, nested comprehensions read rather awkwardly, unlike basically everything else in Python. quote:On the other hand, I do not understand how this code can be giving you the result you expect. I would expect it to give you "Product 1" for the first item, then "Product 2" for the second item, and so on until it runs out of product numbers. It works as I expected it to work for one row, which probably should have tipped me off.
|
# ? Aug 28, 2013 21:06 |
|
Munkeymon posted:Welp, that's the problem - I got the order of evaluation mixed up. Probably why I don't use nested (or even conditional) comprehensions more often and a reason I should: I don't parse them correctly at first glance. In my defense, nested comprehensions read rather awkwardly, unlike basically everything else in Python. The order of for clauses in comprehensions doesn't make sense to me either. Unfortunately it seems (based on my experiences) that is seen as sensible by a majority of Python users, so I guess we're out of luck there. It is not all that often that a comprehension with multiple for clauses is the best and most readable way of expressing something, anyway.
|
# ? Aug 28, 2013 21:47 |
|
Circular imports are bad. I've been splitting my programs into multiple modules as they've increased in complexity. I've generally been able to do it where there's a primary module that calls the others. I'm currently trying to split off a module that needs to update the GUI in the primary module. Is there a clean way to do this without circular imports? Should I just go ahead, but do the import in a function? I need to send a QT signal.
|
# ? Aug 28, 2013 22:32 |
|
Dren posted:When I've needed to parse binary data in python I've always rolled my own stuff with struct.pack/unpack that behaves a lot like Construct. I'll give Construct a shot next time. SWF is an extremely crazy bit-packed format. Instead of being byte-aligned, it simply strings together all bytes into one giant bitstream. To read a rectangle, you first read 5 bits from the stream as an unsigned integer, call it "NBits", then read NBits bits for x, NBits bits for y, NBits bits for width, and NBits bits for height. It's also very inconsistent; sometimes it wants to flush to the next byte boundary, sometimes it doesn't, and the rules for when are very ill-defined. It also gets extremely messy when dealing with endianness. When reading 16 bits, sometimes it wants you to read them in little-endian order, but when reading a non-byte-aligned number of bits, it wants you to read them in big-endian order always. And that's just about parsing the bitstream. There's other craziness layered on top.
|
# ? Aug 28, 2013 23:21 |
|
I hope this isn't a dumb question, but I'm still wrapping my head around generators... I'm using all() to check a really large list (~5000 elements) and currently it's done this way: if all([test(x) for x in X]): dostuff() Python documentation says all() does this: code:
If I do this with a generator, I can avoid this problem. I think. Suppose the first item fails the test. all((test(x) for x in X)) would create one generator object, not a list of 5000 items, pass that generator to all(),and then return false after only checking 1 thing. Worst case it only checks 5000 things. Am I understanding correctly?
|
# ? Aug 28, 2013 23:53 |
|
Dominoes posted:Circular imports are bad. Instead of telling the GUI to update, emit a signal from the model/data class. On the GUI side of things, connect to the signal of the model/data class and update the GUI as needed.
|
# ? Aug 28, 2013 23:53 |
|
FoiledAgain posted:I hope this isn't a dumb question, but I'm still wrapping my head around generators... I have not looked at the all() code, but if what you pasted is correct then the loop is exited at the first element that fails the test. The return statement exits the loop. An example: Python code:
accipter fucked around with this message at 00:01 on Aug 29, 2013 |
# ? Aug 28, 2013 23:56 |
|
Say I have a list like [a, b, c, 0, d, e, f, 0, g, h, i]. How do I extract all elements between instances of 0?
|
# ? Aug 29, 2013 00:14 |
|
|
# ? May 9, 2024 11:36 |
|
Pollyanna posted:Say I have a list like [a, b, c, 0, d, e, f, 0, g, h, i]. How do I extract all elements between instances of 0? Python code:
|
# ? Aug 29, 2013 00:18 |