|
Haystack posted:When you go into Settings | Project Interpreter > Python Interpreters is your system python's lib folder included in the paths tab? Yes it's there. After some more research, I've found a bug on the Jetbrains issue tracker for this issue which arose with Ubuntu 13.04, which I am running. Guess I've gotta wait for a fix from Jetbrains. Thankfully, I'm finally experiencing a bug on a piece of software that isn't marked "wontfix" or "lowpriority"! This one's priority is Major!
|
# ? May 7, 2013 22:23 |
|
|
# ? May 9, 2024 04:14 |
|
ShoulderDaemon posted:Note that there exist platforms where the endianness of integers is not the same as the endianness of floats, because the FPU and the ALU were made as separate units by different teams and cobbled together at the last minute or something. Ah, interesting. I've never encountered any such platform, and I wonder how well Python would handle it. It looks like the struct module (Modules/_struct.c) treats whatever system it's running on as having a single native byte order that's defined as part of compiling the struct module. Out of curiosity, what relatively modern CPUs (i.e can run an OS that can run Python) have different endianness for integers and floats?
|
# ? May 7, 2013 22:33 |
|
Lysidas posted:Out of curiosity, what relatively modern CPUs (i.e can run an OS that can run Python) have different endianness for integers and floats? In terms of relatively modern... the whole ARM architecture is fairly modular, and I've seen a few different people independently make ARM-on-FPGA systems where they managed to flip byte order on the FPU, and then proceed to get an operating system running on it. I'm not aware of any actual ASIC-that-has-gone-to-market with such a bug in recent decades, however. Historically, as with most crazy byte order shenanigans, it was more common. Back in the days of external FPUs and non-IEEE-754 there was a lot of room for exciting mismatches.
|
# ? May 7, 2013 22:42 |
|
Jewel posted:Someone pointed out to me that multi-selection editing is in almost every text editor other than notepad. Multi-select handles arbitrary cursor positions, it is not just column editing, mind you, my gif does not illustrate that. For example you could do a find-all for "time" and two keystrokes convert all of them to "times" (right arrow and s) with multi-selection editing. (THIS IS A TERRIBLE EXAMPLE BUT YOU GET THE JIST.) VVVVVVVVVVVVVVVV Scaevolus posted:Select "time", hit Ctrl-D a few times to expand the selection, right arrow, s. Better example (still kinda dumb because search and replace). deimos fucked around with this message at 23:03 on May 8, 2013 |
# ? May 8, 2013 22:03 |
|
deimos posted:For example you could do a find-all for "time" and two keystrokes convert all of them to "times" (right arrow and s) with multi-selection editing. (THIS IS A TERRIBLE EXAMPLE BUT YOU GET THE JIST.) Select "time", hit Ctrl-D a few times to expand the selection, right arrow, s.
|
# ? May 8, 2013 22:44 |
|
Is there a good page for explanation of how class variables work? I'm working on a poker game, and within the game, I have a global called deckStart that's an organized 52 card deck. I then do:code:
|
# ? May 9, 2013 06:42 |
|
Yeah, you're passing it by reference, so you're directly working on deckStart the whole time. You need to use copy from the standard library, or pull the base values from startDeck when you populate the new deck, rather than mutating it.
|
# ? May 9, 2013 07:36 |
|
Maluco Marinero posted:Yeah, you're passing it by reference, so you're directly working on deckStart the whole time. You need to use copy from the standard library, or pull the base values from startDeck when you populate the new deck, rather than mutating it. code:
I feel like I really should read a solid book on Python instead of haphazardly learning it.
|
# ? May 9, 2013 07:49 |
|
Master_Odin posted:Yeah, I just used self.deckStart[:] which makes a copy as I understand it. I guess I'm a bit confused as to when to know when something is passed by reference and when it's not. Running: Everything is passed by reference, absolutely everything. But ints and strings are immutable - can't be changed. Once you have a value of 4, that's it; that 4 can't be changed (to 5 say), though it can be replaced by a new value 5. The reason why += changes a list in place whereas for your integer it acts like "temp = temp + 1" is that the behaviour of += is dependent on the type on its left. It behaves in the one way for lists and in the other for ints, strings and so on. This might seem confusing at first and almost like "cheating", but in fact you can set the behaviour of += for your own types however you want (by defining the __iadd__() method).
|
# ? May 9, 2013 08:45 |
|
Master_Odin, depending on how serious this poker app you're making is, you may want to think about the security implications of the tools you're using. Specifically you may want to look into os.urandom and random.SystemRandom instead of the standard random.Random class (which is what you're actually using when you call random.random(), random.uniform() etc.), as a smart attacker may be able to exploit some patterns in the latter. You could also look into the RNG in the PyCrypto package. More importantly, there's a simpler and better algorithm for shuffling a deck. It's called the Fisher-Yates Shuffle, and it looks like this: Python code:
|
# ? May 9, 2013 10:13 |
|
LOOK I AM A TURTLE posted:Master_Odin, depending on how serious this poker app you're making is, you may want to think about the security implications of the tools you're using. The counterpoint being that unless there's real money involved you can ignore everything in this post (except for the part about random.shuffle, you should use random.shuffle).
|
# ? May 9, 2013 10:44 |
|
Nippashish posted:The counterpoint being that unless there's real money involved you can ignore everything in this post (except for the part about random.shuffle, you should use random.shuffle). Yeah, my main message would be to always look closely at the standard library before reinventing the wheel.
|
# ? May 9, 2013 11:08 |
|
Can someone point me towards a larger Python project that they think has really good unit tests?
|
# ? May 9, 2013 13:14 |
|
PyTables
|
# ? May 9, 2013 19:44 |
|
Hammerite posted:Everything is passed by reference, absolutely everything. But ints and strings are immutable - can't be changed. Once you have a value of 4, that's it; that 4 can't be changed (to 5 say), though it can be replaced by a new value 5. It's more accurate to say that python uses call by object semantics. Every object is stored on the heap, and variables contain a reference to that object. When you pass in a list to a function, the reference is copied. code:
|
# ? May 9, 2013 20:17 |
|
Can someone recommend a library to use to display vector graphics in python? I would like something where i can specify "hairline" or zero width lines and curves that display as 1 pixel wide no matter how zoomed or scaled it is. Also if there is some built in support for zooming that would be great. Also support for Bezier curves would be nice. It would be for a simplistic 2D CAD sort of application.
|
# ? May 9, 2013 21:22 |
|
peepsalot posted:Can someone recommend a library to use to display vector graphics in python? I would like something where i can specify "hairline" or zero width lines and curves that display as 1 pixel wide no matter how zoomed or scaled it is. Also if there is some built in support for zooming that would be great. Why not use matplotlib and save as SVG?
|
# ? May 9, 2013 21:23 |
|
accipter posted:Why not use matplotlib and save as SVG? SVG doesn't support hairlines for one thing, and there are other issues I have with SVG that I won't get into, but it looks like matplotlib supports postscript export as well, which I think will work for what I need.
|
# ? May 9, 2013 22:06 |
|
peepsalot posted:Can someone recommend a library to use to display vector graphics in python? I would like something where i can specify "hairline" or zero width lines and curves that display as 1 pixel wide no matter how zoomed or scaled it is. Also if there is some built in support for zooming that would be great. Also support for Bezier curves would be nice. cairo?
|
# ? May 9, 2013 22:07 |
|
Suspicious Dish posted:cairo? Nuthin wrong with postscript if that's what peepsalot is comfortable with
|
# ? May 9, 2013 22:28 |
|
tef posted:It's more accurate to say that python uses call by object semantics. Every object is stored on the heap, and variables contain a reference to that object. When you pass in a list to a function, the reference is copied. Yeah, I knew I was most likely not using the correct terminology. I hoped to just get across the idea of how Python behaves and what's going on with Master_Odin's code.
|
# ? May 10, 2013 03:29 |
|
tef posted:It's more accurate to say that python uses call by object semantics. Every object is stored on the heap, and variables contain a reference to that object. When you pass in a list to a function, the reference is copied. What's really happening is that x is added to a dict containing the attributes of foo, and the value of x is the id of a. So it's definitely passing a reference to an object, not the object itself. But then x = 1 creates a new int with a value of 1 and assigns its id to x. When foo ends, a obviously still refers to that old int. If a were mutable you could change it from inside foo. But anything after an assignment would be referring to a different object. Basically python is just a giant pile of dicts.
|
# ? May 10, 2013 07:33 |
|
Hey guys, I'm a total programming novice, who has decided to pick up Python for fun. I'm currently going through the Al Sweigart books and loving around with doing a simple roguelike-like as an excercise. Which directly led me to wasting half a day on this retarded problem: Why does this weird poo poo appears at the beginning of each line and how do I get rid of it? It's probably the most obvious thing in the word, but I can't get around it. It's in pygcurse, if that changes anything. Lichtenstein fucked around with this message at 19:41 on May 10, 2013 |
# ? May 10, 2013 19:07 |
|
Are you using simple print statements or are you doing some kind of loop to output the text? Can you paste the code snippet for just that section?
|
# ? May 10, 2013 19:25 |
|
Currently it's basically this thrown in a loop along with a second function that simply changes the text color. win is my .PygcurseWindow:code:
I've loaded a system font (Consolas), but both courier and the default font also produce these boxes (though without question marks inside, but that's probably just a font thing).
|
# ? May 10, 2013 19:40 |
|
I seem to be a huge idiot today. I have this: Python code:
Lichtenstein posted:Currently it's basically this thrown in a loop along with a second function that simply changes the text color. win is my .PygcurseWindow: Try not having indent=True because it looks like it's trying to use some special character that isn't in your charset and doesn't seem indented anyway. Smarmy Coworker fucked around with this message at 19:47 on May 10, 2013 |
# ? May 10, 2013 19:45 |
|
ARACHNOTRON posted:Try not having indent=True because it looks like it's trying to use some special character that isn't in your charset and doesn't seem indented anyway. The weird characters are left, except everything after the first line snaps to the left window border (which pretty much what indent=False is meant to do). [edit] I've temporarily dealt with it by splitting the thing into separate strings for each line and manually placing them above each other, but there's got to be a better way. Lichtenstein fucked around with this message at 21:08 on May 10, 2013 |
# ? May 10, 2013 21:06 |
|
try os.linesep instead of \n?
|
# ? May 10, 2013 21:24 |
|
Okay, I think it might be because it's Friday, but seriously, what the gently caress, Python?code:
I've never had this problem with any other module, is there something really stupid I'm doing? I've never had a problem with modules only working from the folder I installed them from. Maybe an OSX bug? Or a result of the hosed up permissions on my work computer? edit: File content I'm running: code:
Civil Twilight posted:You have a file noise.py in ~/python_stuff/tests. When you try to "from noise import pnoise2" it's looking in your noise.py rather than the noise module you installed. Looks like noise.py also has "from noise import pnoise2", so it looks in itself... Haha, holy poo poo! Well now, that is embarrassing. Thanks, Civil Twilight! Winkle-Daddy fucked around with this message at 00:19 on May 12, 2013 |
# ? May 10, 2013 21:28 |
|
I'm parsing a CSV and have about 24,000 of these queries I need to run:Python code:
I thought running all the SELECT's at once and then using their output as a parameter in executemany() would work, but doing a for loop and execute()'ing each SELECT statement took just as long. I'm stuck as to whether or not I should just resign myself to the fact that it's going to take for-loving-ever to run this script and let it do its thing overnight whenever I need to run it. IAmKale fucked around with this message at 22:13 on May 10, 2013 |
# ? May 10, 2013 22:10 |
|
nm
BeefofAges fucked around with this message at 02:57 on May 11, 2013 |
# ? May 11, 2013 00:41 |
|
Winkle-Daddy posted:Okay, I think it might be because it's Friday, but seriously, what the gently caress, Python? You have a file noise.py in ~/python_stuff/tests. When you try to "from noise import pnoise2" it's looking in your noise.py rather than the noise module you installed. Looks like noise.py also has "from noise import pnoise2", so it looks in itself... Civil Twilight fucked around with this message at 01:21 on May 11, 2013 |
# ? May 11, 2013 01:19 |
|
Karthe posted:I'm parsing a CSV and have about 24,000 of these queries I need to run: Yuck, first of all, you should be using sqlalchemy's text escaping feature to interpolate in strings unless you're sure there can't be a sql injection attack. Second, take a step back. Do you understand what that query is doing? You're basically inserting table for each value of w and selecting based on id1 and id2. You might want to see if you can create a table based on id1, id2 and w and see if you can't construct the "words" table in one go using a few joins. You'll want to check out the sql questions thread since your problem is an ETL one more than a python one. Third, do you undestand what "BEGIN TRANSACTION" means in the context of whatever sql implementation you're using? You should read the docs on cursor to see if you can disable the implicit transactions, or just find a better way to do standard inserts- postgres supports direct csv loading via psql and you can get very simple csvs (no nesting and quotes) into sqlite3 using the command line. Really, whenever you run bunch of queries the question to ask is not "how do I speed this up?" but "what relationship between the parameters and the query am I missing"? Tables are cheap, time is not.
|
# ? May 11, 2013 01:40 |
|
Do you have an index on the value column of table to make your selects fast?
|
# ? May 11, 2013 03:28 |
|
Malcolm XML posted:Yuck, first of all, you should be using sqlalchemy's text escaping feature to interpolate in strings unless you're sure there can't be a sql injection attack. That said, I suppose you're right that this is more of a SQL thing. I'll take my question to that thread. Dren posted:Do you have an index on the value column of table to make your selects fast? IAmKale fucked around with this message at 03:32 on May 11, 2013 |
# ? May 11, 2013 03:28 |
|
Edit: Double post
|
# ? May 11, 2013 03:32 |
|
How can I write to CSVs without getting a blank row between each real row? This page shows that the file needs to be written in binary mode to do this, but when I do it, I get the following error: 'TypeError: 'str' does not support the buffer infercace.'. Is there a way to convert a string to binary first? I've been able to work with CSVs successfully before when downloading raw CSVs from websites, which work in binary mode. Now that I'm trying to make my own to save data, I'm running into this. example: Python code:
edit: Solved. The correct open line is: Python code:
Dominoes fucked around with this message at 04:10 on May 11, 2013 |
# ? May 11, 2013 03:34 |
|
If there is a SQLite bottleneck with that statement you could probably do the queries 1000 at a time into a python list, them batch write them to the other table. Both of those ops should be fast.
|
# ? May 11, 2013 03:57 |
|
Karthe posted:
|
# ? May 11, 2013 05:40 |
|
|
# ? May 9, 2024 04:14 |
|
ShoulderDaemon posted:Note that there exist platforms where the endianness of integers is not the same as the endianness of floats, because the FPU and the ALU were made as separate units by different teams and cobbled together at the last minute or something. ...and didn't lead to a round of project managers getting laid off for loving incompetence.
|
# ? May 11, 2013 06:12 |