|
Suspicious Dish posted:No, because you should always use absolute imports. You need to ensure that your PYTHONPATH is set correctly. This was it, thanks. Red Mike posted:I suggest using something like nose for running your unit tests. It should set the PYTHONPATH itself, and find your tests itself without any issues when run from the base folder "rl". I'm gonna check this out, thanks.
|
# ? Jan 5, 2013 19:01 |
|
|
# ? May 8, 2024 18:09 |
|
I found a code snippet online that I was hoping someone could explain. code:
code:
fake edit: Pressing tab inside code tags adds spaces, outside it focuses the submit button. That is awesome.
|
# ? Jan 8, 2013 21:45 |
|
Clanpot Shake posted:I found a code snippet online that I was hoping someone could explain. pre:setdefault(key[, default])¶ If key is in the dictionary, return its value. If not, insert key with a value of default and return default. default defaults to None. so, for each key-value pair, get the list at the value's location. If it doesn't have a list, insert an empty list. Then, insert the key into that list and move on to the next one.
|
# ? Jan 8, 2013 21:52 |
|
Clanpot Shake posted:The function declares 'inv', but never appears to assign it Python doesn't have declarations. It assigns it right at the top, there.
|
# ? Jan 9, 2013 02:57 |
|
Suspicious Dish posted:Python doesn't have declarations. It assigns it right at the top, there. code:
code:
The Gripper fucked around with this message at 03:27 on Jan 9, 2013 |
# ? Jan 9, 2013 03:21 |
|
The Gripper posted:I think he means there's nothing writing values into inv, which is easy to assume because of how it's using setdefault and a list default: Thank you, this is very helpful. What is this kind of implicit modification called (appending to keys to modify inv)? And how do I know when a function returns something that can be modified in that way?
|
# ? Jan 9, 2013 14:58 |
|
Clanpot Shake posted:Thank you, this is very helpful. What is this kind of implicit modification called (appending to keys to modify inv)? And how do I know when a function returns something that can be modified in that way? When you assign to a variable it doesn't make a copy of the value, it makes a reference to it. If you make a change to a mutable type it will change in-place (and affect every variable referencing it). If you make a change to an immutable type it will create a new object of that type with the new value and assign a reference to it, so it won't affect any old references. I don't know the full list of what is mutable/immutable off the top of my head, but lists, dicts, and sets are the most common mutable ones you'll come across and most other things are immutable (strings, integers etc.) This page can probably help more with it. (this is the reason why using lists and dicts as default arguments in functions is a bad idea)
|
# ? Jan 9, 2013 15:30 |
|
http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html#other-languages-have-variables This page has more information on names and binding.
|
# ? Jan 9, 2013 16:09 |
|
Anyone have any experience with Kivy? Just wondering about speed, portability, and whether it gets in your face with Cython, or mostly just sticks to Python.
|
# ? Jan 9, 2013 23:50 |
|
Jerry SanDisky posted:Anyone have any experience with Kivy? Just wondering about speed, portability, and whether it gets in your face with Cython, or mostly just sticks to Python. I've been using it a bit. It produces great apps, but its a little bit young. The cython thing you can safely ignore, I do. That said, despite some of it being a bit young and rough around the edges, its supremely well written code and thus very easy to hack on when things dont quite work as expected, and the devs are quite happy to accept patches. I strongly recomend working out of its git repository rather than the prebuilts, just because its bit of a moving target at the moment, and in such cases ,it pays to keep up. The documentation could definately use some work though. Its a giant framework, and not all of it is well documented, and requires a degree of browsing examples and source.
|
# ? Jan 10, 2013 15:05 |
|
I played around with Kivy on iPad2 when it came out officially mid last year and had no problems, I assume it's only gone forward from there. Mind you these were very simple isolated data entry applications, so I wasn't pushing it to it's limits by any means. It actually came in very handy as a prototyping tool for iPad apps: someone suggests a "useful" application and I'd just throw together something with Kivy, trial it on a few users and see how they respond. Even rushed, poorly thought out designs ran well.
|
# ? Jan 10, 2013 15:32 |
|
I'm looking into using Pyramid (formerly Pylons) and I'm looking for some code bases to look at that would give me a good idea of how it is meant to be used. (I know it's lower-level than Django and thus there is more than one way in which it is meant to be used.) Is there, for example, a good example of a simple set of forums, written with Pyramid? Something using backbone.js would be a bonus. Edit: hmm, perhaps the SQLAlchemy + URL Dispatch Wiki Tutorial will suffice. Other suggestions are welcome, though. Victor fucked around with this message at 00:32 on Jan 11, 2013 |
# ? Jan 11, 2013 00:09 |
|
The Gripper posted:I played around with Kivy on iPad2 when it came out officially mid last year and had no problems, I assume it's only gone forward from there. Mind you these were very simple isolated data entry applications, so I wasn't pushing it to it's limits by any means. The .kv stuff is very very nice to prototype with. It sort of reminds me a bit of QTs declarative stuff, but a little less faux-css and a bit more actual widgets. Its very important to pay close attention to the widget lifecycle I've found, as some of the more advanced operations require manipulating it at the canvas level which has impacts on resize/redraws, however the mechanism for dealing with this is quite straight forward so its no big deal. I like it a lot, I just think its documentation could improve a bit. But then again I also think Djangos documentation is poo poo too, and almost nobody agrees with me on that, so take that as you will. e: Oh and someone really needs to go through and update all the info on coordinates with stuff about whether shits working in local or global coordinate spaces, I still havent fully divined the rules for that. vv Incidently, looks like Boa Constructor has been forked and is being worked on again, finally. duck monster fucked around with this message at 09:23 on Jan 11, 2013 |
# ? Jan 11, 2013 01:31 |
|
Victor posted:I'm looking into using Pyramid (formerly Pylons) and I'm looking for some code bases to look at that would give me a good idea of how it is meant to be used. (I know it's lower-level than Django and thus there is more than one way in which it is meant to be used.) Is there, for example, a good example of a simple set of forums, written with Pyramid? Something using backbone.js would be a bonus. Pyramid's documentation lists a few sample applications, and has an easy to overlook tutorial that is somewhat more comprehensive than the wiki tutorials. The example projects are a touch old, but Shootout at least should be informative.
|
# ? Jan 11, 2013 06:01 |
|
I'm using webapp2 to build, well, a web app, and I want to start abstracting a bunch of handlers into separate files to clean up the code and make it more manageable. But I'm at a loss of how to do this well, as I don't understand the python import and inheritance rules terribly well. For instance:code:
I think there's a larger point to be made about using python as my first programming language, because of how easy it is to make working programs that are both powerful and poorly written.... but I can't seem to phrase it correctly.
|
# ? Jan 13, 2013 20:46 |
|
I've been toying with Flask a little bit to try and branch out from Django, especially for smaller projects. One thing I haven't found a very good article or resource on is how to handle making changes to the database schema during development (or even in production). I'm probably hoping for too much to find a South-like project for Flask, but the alternative seems to be to use SQLAlchemy-migrate, which probably works great but is a bit much for me to learn while I'm just getting started. What do you all do in this situation?
|
# ? Jan 14, 2013 17:56 |
|
geera posted:I've been toying with Flask a little bit to try and branch out from Django, especially for smaller projects. One thing I haven't found a very good article or resource on is how to handle making changes to the database schema during development (or even in production). I'm probably hoping for too much to find a South-like project for Flask, but the alternative seems to be to use SQLAlchemy-migrate, which probably works great but is a bit much for me to learn while I'm just getting started. What do you all do in this situation? I don't know if there's a Flask app for it, but Alembic is by the author of SQLAlchemy and i've liked it in the past.
|
# ? Jan 14, 2013 23:40 |
|
Is there a clever way to convert a list of 1d numpy arrays into a 2d numpy array? I thought that just using the array constructor would work but it creates a 1d numpy array of 1d numpy arrays. e: The problem appears to be caused by the array lengths not matching when I thought they did. raminasi fucked around with this message at 21:35 on Jan 16, 2013 |
# ? Jan 16, 2013 21:21 |
|
GrumpyDoctor posted:Is there a clever way to convert a list of 1d numpy arrays into a 2d numpy array? I thought that just using the array constructor would work but it creates a 1d numpy array of 1d numpy arrays. Sounds like you figured it out, but there is numpy._r[..] and numpy._c[..] for concatenation by row and by column.
|
# ? Jan 16, 2013 22:18 |
|
I'm developing a script to automate software installs and decided to use an ini for storing settings and stuff. Is there a better way to get the settings then what I'm doing? I'm using ConfigParser in python 2.7 code:
|
# ? Jan 22, 2013 21:37 |
|
Ashex posted:I'm developing a script to automate software installs and decided to use an ini for storing settings and stuff.
|
# ? Jan 22, 2013 21:42 |
|
Not sure if this is the right thread for my question, but I'm working in Python so I'll start here. I'm having trouble printing unicode in the command prompt window. I first got this UnicodeEncodeError: 'charmap' codec can't encode character u'\u0294' in position 15: character maps to <undefined>. Some googling suggested I type chcp 65001 in the prompt, which appeared to work since I got a confirmation message, but then when I ran the script I got LookupError: unknown encoding cp65001. Suggestions? edit: to clarify, everything works fine when I print to the interactive window in PyScripter, and the same stuff print to file just fine. The problem is printing to screen in the command prompt. FoiledAgain fucked around with this message at 23:02 on Jan 22, 2013 |
# ? Jan 22, 2013 22:22 |
|
The Gripper posted:You could do tssmssql = dict(parser.items('tssmssql')) and then just read tssmssql['dbhost'] etc. to cut out a lot of the repetition. Thanks! That's exactly what I was looking for. I found an example for python 3.2 which didn't work, dict is what I was missing.
|
# ? Jan 22, 2013 22:57 |
|
Has anyone managed to get Kivy working properly with pyinstaller on Windows? It's pretty much the only thing stopping me from moving some important cross-platform products to it at the moment, since I need an easy-to-distribute package for it. The documentation for it (pyinstaller packaging) is absolute trash, the maintainer uses OS X exclusively and seems to have no idea what he's doing with regards to Windows despite committing things with messages that say otherwise. I've spent a few hours dicking around with it and it never seems to package up everything it needs, at least in the final stage. The intermediary collection stage where it puts all dependencies and binaries in one place *seems* to work but I can't tell if it's touching things outside that directory as well. Seems to be PIL causing problems, and I can't figure out why (other people have reported it with no solution).
|
# ? Jan 23, 2013 17:15 |
|
The Gripper posted:Has anyone managed to get Kivy working properly with pyinstaller on Windows? It's pretty much the only thing stopping me from moving some important cross-platform products to it at the moment, since I need an easy-to-distribute package for it. God, I've been having the same issues. One thing I've been meaning to try (but haven't yet) is using a nice portable kivy distribution for packaging, kept separate from my development python environment. This thread gives me hope, though. The group is pretty active.
|
# ? Jan 23, 2013 18:29 |
|
Chosen posted:God, I've been having the same issues. One thing I've been meaning to try (but haven't yet) is using a nice portable kivy distribution for packaging, kept separate from my development python environment. This thread gives me hope, though. The group is pretty active. I was holding out hope that I'd crack the pyinstaller case today, but just now had an issue where pyinstaller generated the right directory and file structure but I could only run the result from the MinGW kivy session. As soon as I tried it on it's own it threw errors about missing DLLs with no stack trace. Annoyingly it happened to only one of 3 test projects, so I'm not even sure where to start troubleshoooting now!
|
# ? Jan 23, 2013 18:48 |
|
Another beginner question for you guys. I'm attempting to use variables inside my config file but keep getting an interpolation error. This is what I have in the config: code:
|
# ? Jan 24, 2013 00:50 |
|
Ashex posted:Another beginner question for you guys. I think you need to be using code:
|
# ? Jan 24, 2013 01:05 |
|
accipter posted:I think you need to be using Well, I'm an idiot. Thanks!
|
# ? Jan 24, 2013 08:05 |
|
Im trying to draw a png with PIL (the 3.2 version here http://www.lfd.uci.edu/~gohlke/pythonlibs/ since its the only version I can find for 3) and it uses stupid amounts of memory. Drawing a 37kb image with putpixel sends usage from 32mb to 700+ and the 5400x1200 one im drawing makes python kill itself at 2GB memory before it gets to 20% complete What else can I use?
|
# ? Jan 26, 2013 08:47 |
|
Probably better off creating an RGBA image with numpy, then PIL has Image.frombuffer for converting an array in one go. Image.putpixel is probably the slowest, least efficient method you could use. Alternatively you could try using the pure python PyPNG library to convert the array, but I have no personal experience with it. .
|
# ? Jan 26, 2013 09:13 |
|
BigRedDot posted:Probably better off creating an RGBA image with numpy, then PIL has Image.frombuffer for converting an array in one go. Image.putpixel is probably the slowest, least efficient method you could use. That works so much better, thankyou!
|
# ? Jan 26, 2013 10:32 |
|
Does anyone have a recommendation for an IRC library that works in Python 3? I really like this library for how simple it is to get something working, but it doesn't support Python 3. I found that it is possible to get it to work in Python 3 by modifying it, but something similar that is supported might be nice.
|
# ? Jan 27, 2013 00:34 |
|
Hammerite posted:Does anyone have a recommendation for an IRC library that works in Python 3? I really like this library for how simple it is to get something working, but it doesn't support Python 3. I found that it is possible to get it to work in Python 3 by modifying it, but something similar that is supported might be nice. https://bitbucket.org/jaraco/irc
|
# ? Jan 27, 2013 00:45 |
|
The Gripper posted:I've always just used irclib, which claims to be Python 3 supported (though I've only used it with 2.7). Installs properly from pip (it's called "irc" rather than irclib though). I recall looking at this, and being turned off by how complex the example bot's code looks. It seems extremely involved just for making a simple robot that responds to messages in a channel, though maybe if you need to do a lot of advanced stuff that complexity is needed. In comparison with the one I linked, you can get going just by writing methods called on_channel_message and on_private_message, which makes things exceedingly simple.
|
# ? Jan 27, 2013 02:46 |
|
I've used Twisted for IRC bots before, but it doesn't yet support Python 3. I guess I don't see why you can't just install Python 2.
|
# ? Jan 27, 2013 03:08 |
|
Hammerite posted:I recall looking at this, and being turned off by how complex the example bot's code looks. It seems extremely involved just for making a simple robot that responds to messages in a channel, though maybe if you need to do a lot of advanced stuff that complexity is needed. In comparison with the one I linked, you can get going just by writing methods called on_channel_message and on_private_message, which makes things exceedingly simple. It seems to work perfectly on this echobot example with varying non-ascii character sets. quote:[13:37:59] <face> 博客- 玉龙的技术博客- 开源中国社区 Honestly though, irclib isn't much more verbose and if you create a base bot that does the hard work from the example (handling server joins, nick collision) you can just subclass that and implement the same as ircutils with almost identical code.
|
# ? Jan 27, 2013 03:48 |
|
Hammerite posted:I recall looking at this, and being turned off by how complex the example bot's code looks. It seems extremely involved just for making a simple robot that responds to messages in a channel, though maybe if you need to do a lot of advanced stuff that complexity is needed. In comparison with the one I linked, you can get going just by writing methods called on_channel_message and on_private_message, which makes things exceedingly simple. You can use the irc controller from this: https://github.com/priestc/giotto It uses irclib (someone in this thread wrote the code), and it supports python3. Write your function, plug it into the manifest, configure the controller file with your irc server name/channel/etc, then execute the controller. Viola, instant irc bot.
|
# ? Jan 27, 2013 03:58 |
|
how!! posted:You can use the irc controller from this: https://github.com/priestc/giotto Trap sprung.
|
# ? Jan 27, 2013 04:31 |
|
|
# ? May 8, 2024 18:09 |
|
Hammerite posted:Does anyone have a recommendation for an IRC library that works in Python 3? I really like this library for how simple it is to get something working, but it doesn't support Python 3. I found that it is possible to get it to work in Python 3 by modifying it, but something similar that is supported might be nice. Comedy option: Port ircutils to python3; 2to3 might get you most of the way too.
|
# ? Jan 27, 2013 09:20 |