|
lufty posted:i'm not quite sure how this fits in? Its literally the answer to your question. In your code you have Python code:
If you change RollRepeat to return True if the user says yes and False if the user says anything else, how could you use that in your loop?
|
# ? Apr 7, 2014 15:28 |
|
|
# ? Apr 25, 2024 11:41 |
|
Dirty Frank posted:Its literally the answer to your question. idk this? Python code:
|
# ? Apr 7, 2014 16:01 |
|
Look again at SurgicalOntologist's post, Python code:
If I rewrite the SO's loop as this is it more clear? Python code:
|
# ? Apr 7, 2014 16:56 |
|
lufty posted:idk this? Dirty Frank was trying to get you to assume that RollRepeat() is the function responsible for checking what the user says. In which case you could use it in place of the True in "while True". code:
code:
code:
If you have a long return value that you want to split onto two lines then you do have options: code:
code:
|
# ? Apr 7, 2014 16:57 |
|
Hammerite posted:Dirty Frank was trying to get you to assume that RollRepeat() is the function responsible for checking what the user says. In which case you could use it in place of the True in "while True". okay I'm just trying to fit this all together in my head if I gave you the code: Python code:
|
# ? Apr 7, 2014 17:30 |
|
OK, I notice that the code you posted is different in at least one important respect, which is that you changed the behaviour of RollRepeat() so that it calls exit() if the user types "No". If you go with that, then you actually don't need to change the while loop (although you do need to get rid of the "return" line and everything after it):code:
code:
code:
|
# ? Apr 7, 2014 17:59 |
|
Hammerite posted:OK, I notice that the code you posted is different in at least one important respect, which is that you changed the behaviour of RollRepeat() so that it calls exit() if the user types "No". If you go with that, then you actually don't need to change the while loop (although you do need to get rid of the "return" line and everything after it): okay now I'm getting a traceback error Python code:
|
# ? Apr 7, 2014 18:28 |
|
lufty posted:okay It's True, not true.
|
# ? Apr 7, 2014 18:32 |
|
Thermopyle posted:It's True, not true. okay, it's working fine now, thanks a lot
|
# ? Apr 7, 2014 18:38 |
How come these produce different results?code:
|
|
# ? Apr 7, 2014 19:42 |
|
fletcher posted:How come these produce different results? Python code:
Looks like it Python code:
|
# ? Apr 7, 2014 20:10 |
|
Is there a reason (beyond not wanting to have yet more numeric magic methods to define) why there is no __riadd__() (or __iradd__()), etc.? __add__() is so that you can do self + other __radd__() is so that you can do other + self (if the class of other doesn't know how to add instances of your class) __iadd__() is so that you can do self += other but you can't customise other += self?...
|
# ? Apr 7, 2014 21:25 |
|
Is there a situation where that would make sense? It seems to me like you'd always want to use the radd behavior here. Since other += self is (supposed to be) equivalent to other = other + self, from the perspective of self these are both the same: radd.
|
# ? Apr 7, 2014 21:33 |
|
SurgicalOntologist posted:Is there a situation where that would make sense? It seems to me like you'd always want to use the radd behavior here. Since other += self is (supposed to be) equivalent to other = other + self, from the perspective of self these are both the same: radd. But surely you can use the same logic to argue that __iadd__ is also not needed. SurgicalOntologist posted:Is there a situation where [__iadd__, as it currently exists] would make sense? It seems to me like you'd always want to use the add behavior here. Since self += other is (supposed to be) equivalent to self = self + other, from the perspective of self these are both the same: add. Now re-reading over that transformed post, I see that I haven't really done it right. Specifically, in the last sentence "from the perspective of self" would need to be "from the perspective of other". I guess then the question might be why is the perspective or role of self key. If we can provide a special method for in-place alteration of self, why not provide a way to alter other in place too? On another note, it is annoying that it is standard to use "self" for the self parameter in Python. "(self, other)" is clearly not as good as "(this, that)"...
|
# ? Apr 7, 2014 22:51 |
|
I would answer your question and say that one motivation for having __iadd__ in addition to __add__ is to avoid the unnecessary instantiation of a new object. You could make the same argument for __riadd__, of course, but I can't think of an example where you wouldn't be better off putting the behavior in the other class's __iadd__ method. Yes, the same argument could be used against __radd__ but the augmented case requires more knowledge of the object's internals. So I think __riadd__ doesn't make sense because you need to know more about other than is (meant to be) public. I'm just thinking this through though, I'd be curious what someone more experienced thinks. This got me thinking about a related issue... is there a way to define an attribute of a class, and say "when something tries to use an arithmetic operation on me, use this" or "when someone tries to use the sequence protocol on me, use this". I guess it could work something like: Python code:
SurgicalOntologist fucked around with this message at 23:20 on Apr 7, 2014 |
# ? Apr 7, 2014 23:16 |
|
It sounds like that sort of behavior extends the addition logic of an object beyond its scope. The more explicit method of subclassing the other object and overriding it's add functionality would reproduce the same results, wouldn't it? On a side note, I've now deployed our first Python project as a Markdown -> Sharepoint management tool but there is one Windows user in our otherwise Linux/Mac. Has anyone had any experience cross-compiling pip wheels for the Win platform or should I just skip the headache and distribute an exe?
|
# ? Apr 7, 2014 23:18 |
|
Python code:
|
# ? Apr 9, 2014 14:04 |
|
lufty posted:
Assuming I understand what you are asking, this will prompt the user if they want to continue after an error: Python code:
|
# ? Apr 9, 2014 15:56 |
|
I asked this in Djagno thread, but it should probably go here: Does anyone know the best go-to library or whatever to generate custom QR codes? I'm looking to generate and then store the GIF or whatever they create as a binary in postgres.
|
# ? Apr 10, 2014 00:32 |
|
Ahz posted:I asked this in Djagno thread, but it should probably go here: I used this: https://pypi.python.org/pypi/qrcode with much success in a project. I have no idea if it's the "Best" but it generated QR codes really fast and didn't blow up, and somebody as dumb as me could figure out how to use it.
|
# ? Apr 10, 2014 00:44 |
|
I tried using twitter's pants tool to build a pex file yesterday and couldn't even get the hello world tutorial to work. It might be python 3 only or something? I dunno.
|
# ? Apr 11, 2014 15:38 |
|
I've been mucking about with tkinter to make a user interface for a small film producer Tycoon like game. I've figured out getting images and buttons to appear on the same window, but I cannot for the life of me make the button appear to the right of the image. I've messed with column, row, columnspan, rowspan, pad, sticky, etc. every which way 'til Sunday and the button just stays above the image. Any pointers?
|
# ? Apr 14, 2014 21:11 |
|
Sirocco posted:I've been mucking about with tkinter to make a user interface for a small film producer Tycoon like game. I've figured out getting images and buttons to appear on the same window, but I cannot for the life of me make the button appear to the right of the image. I've messed with column, row, columnspan, rowspan, pad, sticky, etc. every which way 'til Sunday and the button just stays above the image. Any pointers? Double-check that the button and image are in the container widgets you expect them to be in. Something along these lines should normally work (with the usual tk importing stuff cut out): code:
code:
|
# ? Apr 14, 2014 22:50 |
|
Thanks, I'll have a look into that - the solution I eventually ended up with worked nicely but it's probably gonna break the moment I start adding the other widgets I've still got to include.
|
# ? Apr 14, 2014 23:15 |
|
Just got home from pycon. Lots of good talks. They're all available online at http://www.pyvideo.org/category/50/pycon-us-2014
|
# ? Apr 15, 2014 04:42 |
|
BeefofAges posted:Just got home from pycon. Lots of good talks. They're all available online at http://www.pyvideo.org/category/50/pycon-us-2014 Sweet, Fast Python, Slow Python answers some questions I was just wondering about how to write efficient code for PyPy. I'm trying to do Google Code Jam with PyPy, so knowing how to write well-behaved code is helpful.
|
# ? Apr 15, 2014 07:32 |
I lost a bunch of my bookmarks recently, and I'm looking for a github repository that someone had linked here ages ago of a bunch of project ideas (of varying degrees of complexity) that someone learning Python could use to give them some more "practical" experience with coding besides doing CodeAcademy prompts. Does anyone remember what I'm talking about and happen to have a link handy, since I'm not seeing it in the OP? If I remember right, the repository started with a beginner coder keeping track of her little projects, and it gradually snowballed into a place where people could post coding challenges and she'd meet them, and then post examples of her code.
|
|
# ? Apr 15, 2014 10:55 |
|
Drone posted:I lost a bunch of my bookmarks recently, and I'm looking for a github repository that someone had linked here ages ago of a bunch of project ideas (of varying degrees of complexity) that someone learning Python could use to give them some more "practical" experience with coding besides doing CodeAcademy prompts. Does anyone remember what I'm talking about and happen to have a link handy, since I'm not seeing it in the OP? Is it this one? https://github.com/karan/Projects
|
# ? Apr 15, 2014 14:58 |
|
One for the the swarm mind / "what was that thing where": About 18 months - 2 years ago, i used a Python reproducibility / literate programming package to write a bunch of webpages. It was fairly simple and lightweight - write a file of text (restructured text?) with chunks of embedded Python within, and process to get the page with the executed results within. It was just the right level of complexity for doing how-tos and webpages. But I can't remember what it was and googling fails me. It was not: * knitr (although it _like_ that) * Jug * Sumatra * Ipython notebooks * IpEdit * Active Papers * Dexy * Bein * Snakemake Any ideas?
|
# ? Apr 15, 2014 16:06 |
|
outlier posted:Any ideas? Sphinx? http://sphinx-doc.org/
|
# ? Apr 15, 2014 16:48 |
|
Anyone have suggestions for representing events in a pandas DataFrame? I have a DataFrame with a datetime index and I'd like to mark discrete events. Is there a built-in option I can't seem to find or is a separate data structure my best bet (e.g. a dict mapping event types to lists of datetimes). The latter is intuitive enough but it would be nice to pass around just a dataframe rather than a (data, events) tuple. E: why didn't I think of making a column for each event type? My first plan was to a make an 'events' column with values of either None or an event type, but I ran into a problem with simultaneous events. I guess I'll just make separate columns. It will be very sparse but it should work.
|
# ? Apr 15, 2014 17:14 |
|
I feel like I must be missing something obvious here, but how do I change the font of a tkinter menubar? I've got all the cascade options in Arial but can't get the option headers off default.
|
# ? Apr 15, 2014 23:31 |
|
I want to parse a pretty simple BNF. Is pyparsing the way to go? I kind of hate that the main documentation source is "buy the oreilly quickstart guide" or slog through a bunch of other people's examples.
|
# ? Apr 15, 2014 23:45 |
|
Nope. Simple framework - think it processed just a single page.
|
# ? Apr 15, 2014 23:46 |
|
I'm making an application that's thin back-end on Django, thick front end client. While ideally most of the time they're going to be hosting it on a proper server instance, they want it to be easily distributable if required. I would like to find a decent reliable way to package up python, dependencies and code so the server can be run in a one click executable or installer. Its not a big deal if its running on the Django dev server seeing as it would only be used in very light circumstances (1-5 users). Anyone done something similar before and knows some good tools for repeatably bundling it all, ideally I want to set up a largely automated build process for it. Executable size is not a big deal either.
|
# ? Apr 16, 2014 09:46 |
|
Maluco Marinero posted:I'm making an application that's thin back-end on Django, thick front end client. While ideally most of the time they're going to be hosting it on a proper server instance, they want it to be easily distributable if required. Are you trying to target one or multiple operating systems? Which?
|
# ? Apr 16, 2014 14:37 |
|
outlier posted:Any ideas? Pweave?
|
# ? Apr 16, 2014 14:44 |
|
accipter posted:Are you trying to target one or multiple operating systems? Which? Ah sorry, ideally Windows, Mac and Linux, just recent versions to begin with but if I can get more birds with one stone I'll take it. Mac & Linux less of a priority cause the majority of targets will be Windows.
|
# ? Apr 16, 2014 16:15 |
|
Maluco Marinero posted:Ah sorry, ideally Windows, Mac and Linux, just recent versions to begin with but if I can get more birds with one stone I'll take it. Mac & Linux less of a priority cause the majority of targets will be Windows. Would something like cx_freeze work for you? http://cx-freeze.sourceforge.net/
|
# ? Apr 16, 2014 20:11 |
|
|
# ? Apr 25, 2024 11:41 |
|
https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txtquote:Variable, module, function, and class names should be written between single back-ticks (`numpy`). Doesn't it have to be :mod:`numpy`? At first I thought that the line above implied that numpydoc automatically figures out what your references are, but all it's doing for me is italiczing with single back-ticks. Am I missing something? Is there some setup required to avoid having to explicitly use :class:, :mod:, etc?
|
# ? Apr 17, 2014 01:38 |