|
The King of Swag posted:Serialization: I realize that Python has the pickling functionality, but it's inherently unsafe and apparently does way more than I actually want it to (just save the values of the instance variables; I don't care about restoring the object itself). In the end I've resorted to writing my own serialization code utilizing the struct class--unfortunately the lack of fine-grained data control and the beauty that are void pointers actually makes this much more complicated than the equivalent C code. This should do the trick. Python code:
|
# ¿ Aug 13, 2012 11:21 |
|
|
# ¿ May 19, 2024 20:46 |
|
The King of Swag posted:I've seen that before and the problem is that I need to save my data out as binary and be able to easily read it all back. Using that trick, saving would be easy but loading would require a lot of parsing. My current method of an explicit file format with run lengths embedded for blocks of data is a lot more succinct with no need for parsing of data beyond reading the length of a block, loading that block into memory and reading the next. Although I'm all ears if there is an easy Pythonesque way to load your example. Parsing bad? Json to the rescue! Python code:
|
# ¿ Aug 14, 2012 00:12 |
|
Or you could send the exe http://www.pyinstaller.org/ Works for me.
|
# ¿ Aug 15, 2012 23:42 |
|
JetsGuy posted:Quick (stupid) question. I want to make a bunch of lists before going into a loop (that will append data into these lists). Python code:
Python code:
Some better dict structure would probably be better, as posted above. evilentity fucked around with this message at 00:32 on Dec 6, 2012 |
# ¿ Dec 6, 2012 00:30 |
|
Drunk Badger posted:Here's an example from a routing simulator I'm building. As was said above, you get same values each time because they are evaluated when you add them to the list not in the loop. This does what you want: Python code:
You can also randomize initial nodes with something like that: Python code:
evilentity fucked around with this message at 19:51 on Feb 14, 2013 |
# ¿ Feb 14, 2013 19:48 |
|
Wildtortilla posted:I'm currently taking PSU's Certification in Geographic Information Systems (aka, intelligently using ArcMAP). In May I'll be starting my final course for the certificate and I have a huge array of options, but I'm leaning towards their course in Python. From looking at job postings for GIS positions, I'd wager at least 50% of postings include knowing Python as a desirable skill. However, coming from a background in geology, I have no experience with coding; would the links in the OP be a good place for me to start or should I start elsewhere since I have no experience? The first link in the tutorials "MIT Introduction to Computer Science and Programming" and the contents of this post seem like they'd be a good start for me. Any suggestions? You could try http://learnpythonthehardway.org/ or https://www.edx.org/courses/MITx/6.00x/2013_Spring/about Intro to CS in python. I did previous one and it was pretty fun, but difficulty ramps up quickly after few lectures. Im sure people around here have other suggestions. Python is pretty easy to get into, so with enough determination you will get it.
|
# ¿ Mar 2, 2013 01:26 |
|
Mad Pino Rage posted:I was doing pretty good as in I was writing something. The assignment is to write a main function to call functions for A) list a deck of cards in 52 rows and 3 columns: a number given to each card(0-51), the card itself, and show the location of the card(deck player's hand, computer's hand) B)clear the deck so all cards start in the deck C)assign five cards to each the player and computer D) show the cards in the player's hand and the computer's hand I was bored so I did this for you. Try to use this as guidelines for your own work and dont just copy verbatim. At least try to understand why and how it does things. Ive commented things that I thought might be hard. There is no error checking so you could add that. Python code:
|
# ¿ Mar 23, 2013 12:41 |
|
ARACHNOTRON posted:why is Python so weird?? What is so weird about it? It will search folder the file is in, subfolders, path and libs. It doesnt magically know wheres your stuff located. Try structuring your project in different way. Path is hardly magic. If you really must you can use this: Python code:
Mad Pino Rage posted:Write a loop that traverses: Python code:
Mad Pino Rage posted:Open a file named ch09e02.py and with the following content: Mad Pino Rage posted:Well, I wrote this to pass a doctest in one of the exercises, but I don't understand a piece of code. I actually copied it from another project I wrote earlier in this semester.
|
# ¿ Mar 29, 2013 23:28 |
|
Dominoes posted:Here's the read_cell function: And thats the reason why its so slow. Read the whole file into memory and go from there. I assume reader is csv.reader. Something like that should do: Python code:
|
# ¿ Apr 3, 2013 17:07 |
|
Dominoes posted:Another CSV / memory vs drive write question. If I want to download a CSV from a url, is there a way I can put the file information directly into a variable in memory? I've tried many combinations using list(), read(), csv.reader() etc, but can't find a working solution that skips writing the csv to disk, and reading it. It doesnt work because reader expects file handle not string. Maybe you can use StringIO to makes this easy like this: Python code:
|
# ¿ Apr 6, 2013 02:09 |
|
dantheman650 posted:I added the Python directory to PATH and am still getting that error if I first don't CD to my programs directory, but that's ok - it only takes a second to CD and that works fine for now. You added PYTHONPATH so you can type 'python' in command line. When you do 'python hello.py' cmd knows wheres python, but not hello.py. Thats why you need to cd to your script path first. Alternatively, you can specify full path like so: 'python c:\dev\hello.py'. You can do [ code=python ] for proper python syntax highlighting. evilentity fucked around with this message at 23:41 on May 1, 2013 |
# ¿ May 1, 2013 23:39 |
|
I did a thing: https://github.com/piotr-j/wf_alerts Simple alerts about tweets with specific keywords. Windows only due to winsound. Do your worst.
|
# ¿ Jun 24, 2013 19:59 |
|
DSA_Key posted:So I needed something that could execute commands on multiple Linux systems and bring the data back to me for parsing. So using Python and Pexpect I wrote the following and I just wanted to share as this is the very first project I've ever undertaken in Python let alone Pexpect. The only thing the script doesn't ask for is the file with the IP addresses or hostnames instead it's hard coded to read a targets.txt file in the directory it's executed from. Looks reasonable for most part. Here are few tips: When you use `with` you dont need to close the file. Use logging module for logging. In Python empty string is considered false, thus `if host != "":` is equal to `if host:`. In the `if i == 0:` etc try not to using magic numbers. Just make a constant at the top like `E_TIMED_OUT = 0` Also try using some more meaningful variable names, i's and j's arent very clear. Python's pretty cool!
|
# ¿ Aug 1, 2013 21:56 |
|
digitalcamo posted:Something I've been thinking about while learning Python, is it possible to write iPhone apps using Python? That idea seemed pretty neat as I'm trying to figure out what kind of programming I'd like to pursue. Followed the advice of others and really enjoy Codecademy. Turns out it is not a total waste of time like some of the reviews I read before joining. I havent used it, but Kivy might interest you: http://kivy.org/ Its a multiplatform framework for various systems including ios.
|
# ¿ Aug 2, 2013 19:34 |
|
Rocko Bonaparte posted:On that token, are there patterns you'd see in Python you wouldn't see in your typical statically-typed enterprise language? Unless module is very simple, there really shouldnt be global state in it. Classes arent as ubiquitous as they are in, say, java. Often you can get away with a bunch of functions. Thinks statics in java. If you really need some state, you can nest a bunch of functions as well. But i wouldnt go over board with that. Can we some examples? Maybe anonymize it a litte, if you cant post verbatim.
|
# ¿ Sep 5, 2013 16:05 |
|
NtotheTC posted:
Already give you all unique combinations. Whats your question again?
|
# ¿ Sep 17, 2013 23:01 |
|
Goonicus posted:Just getting into learning, right now going through the Learn Python the Hard Way course. When i started learning python 2 years ago, ive wrote pretty big gui application for company i work for. That was a huge mistake. Wayyy too complicated for first project. Im refactoring it now Your best bet is to try to fix an itch of yours. Automate some mundane task, create a blog. Something reasonably complex, but not too much. Go nuts and learn.
|
# ¿ Oct 9, 2013 14:15 |
|
hemophilia posted:I have a problem where I'm supposed to take the data inside two dictionaries, and multiply them. The conciet of the lesson is that I'm supposed to multiply the 'stock' of my fruit and veggies by their cost for a total potential profit. The website/interpreter keeps spitting back that I'm not returning the right numbers but everything looks right to me, so I'm assuming it wants me to add all of it together for a grand total. print is not return.
|
# ¿ Nov 7, 2013 14:49 |
|
FoiledAgain posted:What's this about? Why the hell do you need this?
|
# ¿ Dec 17, 2013 17:32 |
|
Pollyanna posted:Is there a version of this for PySide? I'm looking to start a GUI version of my stocks app and I like this book, but it's only for PyQt. PySide and PyQt are fairly similar. Bigger issues is that this book is over 6 years old. Ill check it out, hopefully general concept didnt change all that much.
|
# ¿ Dec 30, 2013 08:12 |
|
kalstrams posted:Windows 8.1 x64. How do I make Python 2.7 run from cmd ? Adding C:\python27; to path should be sufficient. Did you restart the cmd prompt? Try instaling normal python in other folder. Maybe the packadge is hosed.
|
# ¿ Feb 3, 2014 15:53 |
|
keyvin posted:My program is corrupting files it copies, and I can't figure out why. I am using the OS module to compare time stamps and copy the files. I do open the files, but only for reading. I did something similar, basically mirror stuff to and from a pendrive. This should do the trick: Python code:
Python code:
|
# ¿ Mar 7, 2014 17:39 |
|
fletcher posted:How come these produce different results? Python code:
Looks like it Python code:
|
# ¿ Apr 7, 2014 20:10 |
|
Akarshi posted:Okay guys, I'm super new to Python and I think this question is Python related. If it's not, though, feel free to point me in the right place. You sure you cant just do messageA == messageB? If you have custom messages you need to implement __eq__ magic method.
|
# ¿ Jun 19, 2014 00:20 |
|
|
# ¿ May 19, 2024 20:46 |
|
Also dont start instance variable name with Capital letter.
|
# ¿ Jun 20, 2014 12:08 |