|
Pollyanna posted:The URL I'm sending arguments to is /get?username=asdf&password=asdf. I just get a 400 when I do this. What am I doing wrong? You said you moved on, but what's causing the problem is (probably) that you are using GET. Notice how your data is being sent in the URL (BTW, Passing a password in the url is always a big no-no), not in a JSON. You should use POST instead. And you probably have to fiddle with the Content-Type somewhere. Pollyanna posted:Now I just wish SQLAlchemy stuff was more easily serializable. I hear ya.
|
# ¿ Apr 19, 2014 03:10 |
|
|
# ¿ Apr 27, 2024 11:16 |
|
I don't have python on this machine, butcode:
Edit: person below me knows what's up. Space Kablooey fucked around with this message at 20:32 on May 10, 2014 |
# ¿ May 10, 2014 20:30 |
|
For every item ("_", in this case) in the iterable (s.split(',')), call method .strip() of that item and put that item in a tuple. Utimately, it results in a tuple like this: ("115 Berry Lane", "Plano", "TX 24134") For more explanation: https://docs.python.org/2/tutorial/datastructures.html#list-comprehensions
|
# ¿ May 10, 2014 20:54 |
|
Cultural Imperial posted:What do you guys use for templating? Jinja2? I use Jinja2, but I'm using flask, so.
|
# ¿ May 16, 2014 04:11 |
|
How is dogs.append(first) not throwing a NameError in your print method? By the way, in addition to the __str__ magic method, you can do someting like this: Python code:
I suggest you also look into a bit called @classmethod, and see how it differs from @staticmethods and regular methods. Anything not clear, please ask! Space Kablooey fucked around with this message at 04:46 on Jun 11, 2014 |
# ¿ Jun 11, 2014 04:41 |
|
hlfrk414 posted:I would not suggest giving a new python programmer decorator methods either; just define a function outside the class. It's the simplest to understand and a good habit to build first. Functions that don't act on the class object or the instance can be plain functions. Not harpin' on you for helping though. Fair enough. I don't know decorators methods myself as well as I should, and I really should brush up on that. What I wanted to say with that, is that he should look up static classes/methods, but in the general OOP context. That it was implemented via a decorator method just muddled things up.
|
# ¿ Jun 11, 2014 18:02 |
|
the posted:...Go on... You are probably firing two or more of those: One may be: SELECT id_butt, whatever1 FROM butts And the other may be: SELECT id_fart, id_butt, whatever2 FROM farts The result is that you have now two separated sets of data that are logically related. Modern databases are handy in that relational databases are all the rage for quite some time now. Instead of having two sets of separated but related data, you can have only one set of related data, saving you the hassle of JOINing them yourself. The database excels in that already. Something like this: SELECT b.id_butt, b.whatever1, f.id_fart, f.whatever2 FROM butts b, farts f WHERE f.id_butt = b.id_butt; My SQL is quite rusty, so that may not be quite right (sqlalchemy ), so I'll just leave you a link to the CoC SQL megathread. Sorry for not being more helpful.
|
# ¿ Jul 3, 2014 03:57 |
|
theguyoncouch posted:Said friend here. This is how mine ended up. first time with python but i tried to cover all my bases. probably not the best Don't use tabs. Use spaces, preferably 4.
|
# ¿ Jul 3, 2014 23:24 |
|
Thermopyle posted:You also need some blank lines for readability. I can't think of the studies right now to quote, but something like this: qntm posted:Set your tab size to a single space, then indent using four tabs. The best option, IMO, is to set tabs to convert to four spaces.
|
# ¿ Jul 4, 2014 03:18 |
|
GET requests can time out, but they shouldn’t time out because you took a long time between two of them. This is working: Python code:
|
# ¿ Jul 8, 2014 17:41 |
|
e: disregard
|
# ¿ Jul 16, 2014 20:44 |
|
code:
|
# ¿ Jul 18, 2014 18:47 |
|
I need to parse ISO 8601 dates and I found the dateutil module (https://pypi.python.org/pypi/python-dateutil/1.5). However, the latest version for python 2.X is 1.5, which is 4 years old by now. Is there any recommendations against it?
|
# ¿ Jul 20, 2014 17:35 |
|
I thought the author just picked all those versions as a catch-all. Thanks.
|
# ¿ Jul 20, 2014 18:25 |
|
Looks very interesting. Will take a look as soon as possible. Thanks.
|
# ¿ Jul 20, 2014 21:56 |
|
the posted:I have a technical interview for a Python position today at 4:30. Well, good luck!
|
# ¿ Aug 5, 2014 17:01 |
|
ShadowHawk posted:
You crashed my computer, so yes. EDIT: Changed zip to itertools.izip and it worked in python 2.7 Space Kablooey fucked around with this message at 20:21 on Aug 11, 2014 |
# ¿ Aug 11, 2014 20:10 |
|
Crosscontaminant posted:Your computer symlinks python3 to a Python 2 instance? That's a bit dubious. I'd do something about that, like installing Python 3. Nah, it was my own fault, am I'm used to writing just "python" in the command line: "Oh, this is Python 3 code, I just have to import print function and it will work. What can go wrong? "
|
# ¿ Aug 11, 2014 23:23 |
|
map is a function that is always available for every script, so you can't have anything that is called "map" https://docs.python.org/2/library/functions.html https://docs.python.org/3.4/library/functions.html __getitem__ is what the "array[i]" actually calls down in the guts of python: https://docs.python.org/2/library/operator.html#operator.__getitem__ Space Kablooey fucked around with this message at 05:06 on Aug 14, 2014 |
# ¿ Aug 14, 2014 05:02 |
|
KICK BAMA KICK posted:So either you mistyped map in place of something else (like fov_map perhaps?) or you need to incorporate the code that defines map. In the unlikely event that this code does redefine a very basic and useful built-in function rather than simply coming up with a unique name, consider learning from another source because that's a huge red flag. Also this again, for effect.
|
# ¿ Aug 14, 2014 05:09 |
|
QuarkJets posted:This seems like a reasonable path to take. Feel free to ask any questions in here What you posted isn't what virtualenv sets out to do?
|
# ¿ Aug 14, 2014 13:19 |
|
Poison Mushroom posted:A class is a sort of blueprint for making an object or a function, something you'll need to do a lot. Classes are to functions as constants are to magic numbers. If I wanted to create a lot of gamemaps, then it would behoove me to make a Class for them, something to repeat the map-making code over and over. Something like Floor or Level. In a nutshell, yes, that is pretty much it.
|
# ¿ Aug 14, 2014 19:49 |
|
Dominoes posted:Looking for help parsing XML files. I have long files - I want to pull some of the information into database entries. I used https://pypi.python.org/pypi/xmltodict some time ago and it worked well. Not sure about its performance on large files. EDIT: Murodese posted:Really, really bad. I was using xmltodict to read 300kb-1.5mb XML files and changing it to use XPath resulted in a speedup of something like 15,000%. Ouch Space Kablooey fucked around with this message at 15:31 on Sep 2, 2014 |
# ¿ Sep 2, 2014 04:27 |
|
There's probably a better way, butPython code:
|
# ¿ Sep 10, 2014 17:03 |
|
See if this works:Python code:
Python code:
|
# ¿ Sep 18, 2014 14:22 |
|
Python code:
Python code:
|
# ¿ Sep 18, 2014 15:06 |
|
Hughmoris posted:
Is it working on your end? Isn't opening two file pointers to the same file wrong? EDIT: Stupid bold tags don't work inside code. Space Kablooey fucked around with this message at 14:22 on Sep 26, 2014 |
# ¿ Sep 26, 2014 14:19 |
|
e: nevermind
Space Kablooey fucked around with this message at 20:52 on Oct 6, 2014 |
# ¿ Oct 6, 2014 18:29 |
|
lotor9530 posted:Damnit. I feel like an idiot now. One way to deal with SyntaxErrors is to take a break for a little while and then come back.
|
# ¿ Oct 7, 2014 19:36 |
|
I'm unclear on what you actually want, but maybe this?Python code:
Python code:
Space Kablooey fucked around with this message at 18:43 on Oct 20, 2014 |
# ¿ Oct 20, 2014 18:40 |
|
Begall posted:I do have control over the schema, but I've been making changes to it quite rapidly through a web admin tool, so it seemed easier to just reflect it rather than go through and update the code each time. address_data is simply the name of the table, and represents the table so that I can do things like: You should look at alembic. It generates migrations for your database (creating tables/fields, altering them, etc.) based on your SQLAlchemy models.
|
# ¿ Jan 20, 2015 16:55 |
|
Mocking is something like this: Python code:
The tricky part of mocking is that you mock where the imported function being used, not where it was declared. For example: Python code:
|
# ¿ Feb 4, 2015 20:34 |
|
Gothmog1065 posted:Hey guys, I'm relearning python, and doing it via code academy. I'm trying to be dumb and do things a step above, and I suppose make it.. different? Dunno, trying things, but I can't remember if I can do a for loop like this: Do you mean this? Python code:
code:
Space Kablooey fucked around with this message at 17:10 on Feb 18, 2015 |
# ¿ Feb 18, 2015 16:31 |
|
I started with the mega-tutorial. I'm also working with it for almost two years now, if you hit a snag I can probably help you.
|
# ¿ Feb 19, 2015 03:30 |
|
Instead of executemany, try using execute. Also, you should use the row own id instead of a counter to put in the WHERE clause. Also, if you really want to use a counter (you shouldn't in this case), you should take a look at the enumerate built in. edit: don't do that.
|
# ¿ Mar 29, 2015 04:53 |
|
Your each_patient variable should contain information about the row that you are iterating on. If I had to guess, it returns a dictionary mapping each column to a key; You would then access the id value by doing each_patient['Id'] and then you would pass that to execute. For examplePython code:
I'm still not convinced that the executemany wasn't the culprit. See: https://docs.python.org/2/library/sqlite3.html#sqlite3.Cursor.executemany What happens when you print each_patient? Space Kablooey fucked around with this message at 05:09 on Mar 29, 2015 |
# ¿ Mar 29, 2015 05:06 |
|
outlier posted:It's been a few years since I did anything with Django but: it is that easy to just put Django in front of an arbitrary database and use it as the ORM for the site? I seem to recall Django being a bit pernicky about how db's were laid out. Of course, it depends on how complex the object are that you are pulling out and how polluted my memory is by all those frameworks that are really strict about database structure ("must be named foo_id and must be an integer ...") Django is not just a ORM, though, it a really complete web framework that happens to be somewhat opinionated about the structure of your code. Not that it is a completely bad thing, because if you are just starting with web dev, it is easy to pick it up and let it run. Your business logic shouldn't be constrained by your web framework of all things. If you don't like Django's opinions, then there are alternatives like Flask, where it has very little say on how you should do things and it is very extensible, but it is easier to make a mess of your code.
|
# ¿ Apr 1, 2015 14:04 |
|
I can't tell whats wrong, but it's this line:Python code:
code:
|
# ¿ Apr 2, 2015 20:25 |
|
Rocko Bonaparte posted:Is there some peculiar reason why somebody might want to explicitly pass self into an instance method rather than call it from self directly? I can't imagine what's going on. I'm reading some code from somebody I initially was giving a lot of slack since he was generally doing decent software engineering conceptually. However, bells started to go off when I saw some Systems Hungarian Notation. You mean as an other argument other than the standard self? Python code:
|
# ¿ Apr 6, 2015 17:29 |
|
|
# ¿ Apr 27, 2024 11:16 |
|
To me it looks like you have to load your station objects on a dictionary that is a member of the class TemperatureData. Your get_data should be simple enough when you get to that, and if you are stumped on get_stations, you can call a function called dir on that dictionary, and that should give you some ideas.
|
# ¿ May 4, 2015 17:49 |