|
Is anyone willing to look through some code for me and give me a critique? This is the first time I've ever built something that's more than a few lines. I feel like I need a new set of eyes on this to tell me where and what to clean up. The json file in the repo is a sample output and should render nicely with Github geojson features. I think my next step is to break out some of the output functions into their own module. https://github.com/bwainstock/beeradvocate_scraper/blob/master/ba_scraper.py
|
# ? Dec 8, 2014 05:04 |
|
|
# ? May 9, 2024 12:35 |
|
Here's your holiday Bokeh 0.7 * super tight ipython widget integration (no bokeh server required!) * touch ui support finally * lots of new tools: lasso, poly, point select; crosshair, data table, * several more charts types Since SA won't embed vines and I can't be arsed to do better, here are some lovely gfycat gifs
|
# ? Dec 8, 2014 22:19 |
|
Thanks for making/working on Bokeh - seems pretty cool!
|
# ? Dec 8, 2014 22:21 |
|
Tigren posted:Is anyone willing to look through some code for me and give me a critique? This is the first time I've ever built something that's more than a few lines. Minor suggestions from a lazy skim: -PEP 8 says 2 lines between functions that aren't part of a class. Also says put periods at the end of your docstring sentences. Type annotations would clarify what your functions are doing, since it's not obvious for some of them. ie: Python code:
if 'fail' not in response.url: - You should add a comment about what would cause 'fail' to be in the url. Dominoes fucked around with this message at 22:50 on Dec 8, 2014 |
# ? Dec 8, 2014 22:32 |
|
Dominoes posted:Thanks for making/working on Bokeh - seems pretty cool! No need to thank me, I am super grateful that the opportunity came my way!
|
# ? Dec 9, 2014 03:43 |
|
Coin posted:Yeah, I've heard this before. However, our instructor teaches us to "code our comments": basically we write everything out in plain English before actually coding it. I can see why this might not be helpful in a production environment, but I'd be marked down for not having that stuff. code:
code:
Also doing this you would have found the bug in your code more obviously (for party in mp_affiliation is actually not the party -- iterating like that gives you the key not the value)
|
# ? Dec 9, 2014 05:28 |
|
A really good talk on conventions for naming things: https://www.youtube.com/watch?v=YklKUuDpX5c
|
# ? Dec 9, 2014 05:43 |
|
I'm pretty bad (read: green) at knowing how to do things in a way that makes sense in the long run, wondering if there is a good pattern for this. I'm importing strings from files whose ordering is always the same for each file, but always different between files. So, title, author, date / date, title, author. I want to import all of them and then normalize them so I can display/sort them in a readable way. The first way that came to mind to accomplish this was to create an expected_order variable for each file and then do something like: code:
code:
Also, does anyone have a book recommendation for making me better at thinking about code structure/writing maintainable code? I guess design patterns, project structure, etc? I feel like that is something I've just never read about. It could also be that I should just buckle down and read through the source for big popular well-written libraries or something if that's what I think I need to do, thoughts on that as an approach?
|
# ? Dec 9, 2014 06:57 |
|
*whispers "namedtuple"*Python code:
|
# ? Dec 9, 2014 08:00 |
|
Symbolic Butt posted:*whispers "namedtuple"* I was using a dictionary because it allows me to bypass having to reorder the books on/slightly after import but maybe I'm missing something? Say I have: file_1 = title, date, author file_2 = date, title, author file_3 = author, date, title The idea of assigning each book an order list on import and then just zipping them up in a dict was that I could avoid having multiple functions to deal w/ rearranging everything. Would it still be better to use a namedtuple just because book.title is infinitely more readable than [digging[ into[ dicts?]]] e; I guess I'm just super stupid. I could always just have a single function that takes the same kind of expected_order variable and then just rearranges based on that before assigning it to the namedtuple. The March Hare fucked around with this message at 15:21 on Dec 9, 2014 |
# ? Dec 9, 2014 14:45 |
|
Oops I actually thought about it but then forgot to type it out that you can do something like this:Python code:
|
# ? Dec 10, 2014 03:54 |
|
Dominoes posted:Seems pretty good. Thanks for the comments Dominoes. Are type annotations a thing in python? A quick search turns up talk about Guido's PEP proposal, but I didn't see anything official. Would it be better/helpful to just rename the variables (response_data to response_list and city to city_list)?
|
# ? Dec 10, 2014 04:58 |
|
Has anyone in the entire loving world ever gotten setuptools develop mode working? Mine never seems to put the project on the Python path correctly. I thought it was just the weird directory structure in my project, but I then made a dummy project that looks just like this:code:
code:
code:
I'm on OSX, I dunno if that could conceivably have anything to do with it. It looks like it's simply just not reading egg-info files. Considering giving up and writing a bunch of boilerplate scripts that allow me to switch from "dev mode" and "library mode".
|
# ? Dec 10, 2014 12:01 |
|
Symbolic Butt posted:Oops I actually thought about it but then forgot to type it out that you can do something like this: Python code:
|
# ? Dec 10, 2014 13:20 |
|
StormyDragon posted:
_make is order dependent though, which would bring me back to needing a function to reorder each imported_book list which seems sloppier than just passing in the order and zipping it up on creation. As it sits, I can just do something like: code:
It seems like unpacking the dict shuffles the values into the Book by key automatically, so I don't have to make a function to reorder each possible field order. That said, I am far from an expert, so feel free to tell me how wrong I am - because that's what I'm here for.
|
# ? Dec 10, 2014 15:13 |
|
This is basically the only thing I'm saying in this thread, but TMH, have you considered using Pandas?
|
# ? Dec 10, 2014 15:29 |
|
Cingulate posted:This is basically the only thing I'm saying in this thread, but TMH, have you considered using Pandas? It's for an exercise, stdlib only~
|
# ? Dec 10, 2014 15:37 |
|
The March Hare posted:_make is order dependent though, which would bring me back to needing a function to reorder each imported_book list which seems sloppier than just passing in the order and zipping it up on creation. How about; Python code:
|
# ? Dec 10, 2014 16:41 |
|
Tigren posted:Thanks for the comments Dominoes. Descriptive variable names are important, but I don't think you should include the type in the variable name. You could use comments instead. Dominoes fucked around with this message at 23:16 on Dec 10, 2014 |
# ? Dec 10, 2014 23:12 |
|
Also Guido wants to bring something like mypy into core python. In fact, you can use mypy with type annotations right now!Python code:
|
# ? Dec 11, 2014 00:01 |
|
Thermopyle posted:Also Guido wants to bring something like mypy into core python. In fact, you can use mypy with type annotations right now! Dominoes fucked around with this message at 00:31 on Dec 11, 2014 |
# ? Dec 11, 2014 00:28 |
|
I've started using Q to debug code. https://github.com/zestyping/q Anyone ever used this on Windows? I've tried setting an environment variable for TEMPDIR in windows but it doesn't work. I loving love this tool btw. e: figured it out. Need to set permissions to your TEMPDIR to something more permissive. namaste friends fucked around with this message at 20:06 on Dec 11, 2014 |
# ? Dec 11, 2014 19:47 |
|
Cultural Imperial posted:I've started using Q to debug code. https://github.com/zestyping/q If you think that is good you should try out PyCharm.
|
# ? Dec 11, 2014 23:18 |
|
Thermopyle posted:If you think that is good you should try out PyCharm. I am using pycharm! Are you talking about using the debugger?
|
# ? Dec 12, 2014 00:28 |
|
Cultural Imperial posted:I am using pycharm! Yeah. PyCharm has a fantastic debugger.
|
# ? Dec 12, 2014 02:13 |
|
Thermopyle posted:Also Guido wants to bring something like mypy into core python. In fact, you can use mypy with type annotations right now! I really like this, but why not use syntax closer to Cython? I guess this is more pythonic but it would be great if it could all converge such that optionally statically typed data in python could then be easily compiled with cython. Cython is great because it already has integration with numpy and all the C libraries.
|
# ? Dec 12, 2014 03:43 |
|
SelfOM posted:I really like this, but why not use syntax closer to Cython? I guess this is more pythonic but it would be great if it could all converge such that optionally statically typed data in python could then be easily compiled with cython. Cython is great because it already has integration with numpy and all the C libraries.
|
# ? Dec 12, 2014 10:58 |
|
SelfOM posted:I really like this, but why not use syntax closer to Cython? I guess this is more pythonic but it would be great if it could all converge such that optionally statically typed data in python could then be easily compiled with cython. Cython is great because it already has integration with numpy and all the C libraries.
|
# ? Dec 12, 2014 17:30 |
|
I'm still working on my Python text adventure game, and I'm stumbling around deleting objects. It looks like Python doesn't release objects while there's still references to them in memory, so if I've got an item with a use() function that deletes itself (say a single use health potion), but it still exists in the player's inventory, it's still going to sit there. Is there no way to force a deletion of an object that removes it from all containers somehow (I really doubt this... I haven't seen it in other languages and it seems like a dangerous precedent)? Otherwise I'm trying to think on how I'd remove items on use short of returning a boolean back to whatever called it - but then something else is responsible for the actual deletion and removal from the list, rather than the object itself, and that doesn't seem very clean. You might be tempted to say that the player object can be responsible for that since inventory always resides in that, but I've got the game set up so that the player can interact with the room's inventory as well: "Use oil on gate" (which would remove the oil from the player's inventory when using it on the room's gate) or "use fire on torch" (which would remove the fire from the room inventory while torch is in player's inventory). I'd really not rather force everything to be in the player's inventory just because it'd be more convenient.
|
# ? Dec 15, 2014 19:15 |
|
Thermopyle posted:Also Guido wants to bring something like mypy into core python. In fact, you can use mypy with type annotations right now! I understand that that's not the focus and the expected main benefit though.
|
# ? Dec 15, 2014 19:48 |
|
IIRC from reading the announcement or a talk about it or something from a while back, the only implication for performance is that something like PyPy could use it to aid its optimizations. Perhaps numba, though I',m not too familiar with it, or Cython. In the latter case it wouldn't be an increase in performance as much as the same old performance boost but using standard language features rather than however it works now.
|
# ? Dec 15, 2014 19:59 |
|
Mortanis posted:I'm still working on my Python text adventure game, and I'm stumbling around deleting objects. It looks like Python doesn't release objects while there's still references to them in memory, so if I've got an item with a use() function that deletes itself (say a single use health potion), but it still exists in the player's inventory, it's still going to sit there. Is there no way to force a deletion of an object that removes it from all containers somehow (I really doubt this... I haven't seen it in other languages and it seems like a dangerous precedent)? Why not remove the item from the players inventory on use? Python code:
|
# ? Dec 15, 2014 20:18 |
|
Mortanis posted:I'm still working on my Python text adventure game, and I'm stumbling around deleting objects. It looks like Python doesn't release objects while there's still references to them in memory, so if I've got an item with a use() function that deletes itself (say a single use health potion), but it still exists in the player's inventory, it's still going to sit there. Is there no way to force a deletion of an object that removes it from all containers somehow (I really doubt this... I haven't seen it in other languages and it seems like a dangerous precedent)? Add a reference to an inventory instance as an attribute of your item class, set it when adding the item to the inventory, and have the item call a delete method on the inventory within its own use method. Something like this: code:
|
# ? Dec 15, 2014 20:23 |
|
supercrooky posted:Add a reference to an inventory instance as an attribute of your item class, set it when adding the item to the inventory, and have the item call a delete method on the inventory within its own use method. Something like this: That's perfect, thank you. Easily adaptable for creatures in a room as well so that they can drop their items and destroy themselves on death to boot.
|
# ? Dec 15, 2014 22:51 |
|
This is more of a design question. I have a bunch of log files that are generated by a custom application. They need to be forwarded to a Flume of Fluentd server. Aside from telling the original dev to write their log files through syslogd, is there a better way of forwarding this information other than reading it via python script and rewriting it to Flume/fluent?
|
# ? Dec 15, 2014 22:55 |
|
supercrooky posted:Add a reference to an inventory instance as an attribute of your item class, set it when adding the item to the inventory, and have the item call a delete method on the inventory within its own use method. Something like this:
|
# ? Dec 16, 2014 02:30 |
|
Cingulate posted:Not that Python is too slow for me, but is it realistic that building on this, performance benefits will be achieved? I don't think there's anything theoretically wrong with that idea. I haven't heard anyone talking about making that a goal going forward, but it seems like something that would be taken account of in the future.
|
# ? Dec 16, 2014 02:33 |
|
i'm trying to learn python and i'm still very babbyish. i did something like thiscode:
when i print out the records in my array, everything in the model subclass returns the output "<bound method model.name of <__main__.model at blah blah memory address" i get that it's returning the metadata about the attribute i want instead of the value of that attribute because it's not inheriting correctly, but i'm having a hard time figuring out exactly how i'm making this mistake also please feel free to point out any other mistakes and bad conventions i'm doing here, i just started learning how to code
|
# ? Dec 16, 2014 06:36 |
|
Popular Thug Drink posted:i'm trying to learn python and i'm still very babbyish. i did something like this Well, you can delete all of those "pass" lines. Those don't do anything. You also don't need to use int(4), by default 4 is an int. You can use int() to convert a different type (such as a float or a string) into an int Printing a list of class instances will basically print a list of pointers to those instances, rather than the content of the class. This is actually pretty convenient; imaging if a huge class with tons of variables with printed, it'd just be a huge mess. However, you can modify this by defining the __repr__ method, like so: Python code:
Python code:
|
# ? Dec 16, 2014 07:10 |
|
|
# ? May 9, 2024 12:35 |
|
Use the __repr__ method.Python code:
Edit: oops, beaten. That's what I get for leaving tabs open too long.
|
# ? Dec 16, 2014 07:47 |