|
Lurchington posted:Is there a list of characters that are illegal in at least one filesystem? I'm fine with losing some possibly legit characters in the crossfire for at least the first go. You probably want to stick to vfat, since it's still used as a portable file system: http://averstak.tripod.com/fatdox/names.htm You definitely want to avoid :, / and \ since they're used as directory separators on Mac, Unix and Windows respectively. (Actually this is the obsolete usage for Mac, now it uses /, but I think it still supports it or tries to convert or something - safest to ignore it.) Conveniently those aren't in that list anyway. I would also recommend avoiding ! since it messes with the escaping rules on Linux. (It can still be escaped, it's just a hassle.)
|
# ? Oct 14, 2008 15:15 |
|
|
# ? May 23, 2024 17:57 |
|
Lurchington posted:Which I'm fine with doing as long as I know which characters are illegal, which I thought was the issue. I need to investigate OSError, but will that report which characters are illegal? code:
Bozart fucked around with this message at 15:26 on Oct 14, 2008 |
# ? Oct 14, 2008 15:24 |
|
non-alphanumeric catches too much I think. Apostrophe's and commas, parentheses all come up a lot and hurt readability if I nail them. thanks for the response, it forced me to think of the non-alphanumerics I care about. And thanks for the link to the vfat restriction, I think that will be my first go, and on OSError pop a dialog.
|
# ? Oct 14, 2008 15:42 |
|
So, let's talk Editors and IDEs (possibly again). Due to my work situation, I'm working with three main IDEs: IDLE (comes with your installation). Perfectly fine, and if it wasn't for the inability to use tabs I'd probably make it work still.
PyScripter (windows only as far as I know). My first IDE outside of IDLE and I was initially impressed with the presentation and usability. However, after using it more often I've uncovered a few serious gotchas that can actually make you lose time.
Stani's Python Editor (SPE) (written in Python, and cross platform). Probably my preferred environment now after switching to full-time development on OSX and Ubuntu. Visually very similar to PyScripter and has a lot of the same usability enhancements.
I was bored and got into work earlier than normal.
|
# ? Oct 15, 2008 14:30 |
|
Have you tried out Eclipse+PyDev? I just want textmate to have code completion. That's all I want.
|
# ? Oct 15, 2008 15:05 |
|
No, and I can honestly say I was scared off because I have irrational fear of anything related to Java. Emphasis on irrational.
|
# ? Oct 15, 2008 15:09 |
|
Lurchington posted:So, let's talk Editors and IDEs (possibly again). I gotta say that after messing around with python stuff in windows and getting fed up with mingw and other bullshit, it was an absolute breeze to install ubuntu on my spare computer, install spe, and good to go with everything.
|
# ? Oct 15, 2008 15:18 |
|
Lurchington posted:No, and I can honestly say I was scared off because I have irrational fear of anything related to Java. Emphasis on irrational. I'd give it a try: It helps out quite a bit and is actually pretty nice - my biggest beef with it is that it is "AN IDE", and I'm more of a minimalist. That, and I can't figure out how to change the color that pydev uses when it highlights all occurrences of a symbol in the current file.
|
# ? Oct 15, 2008 16:25 |
|
I'm still fairly new to Python, and I'm working on writing a module that needs to dynamically discover and import its own submodules. Basically, the structure of it looks something like this, and I'll use the names here in place of the actual names of the module I'm writing for simplicity: Module/ - script1.py - script2.py - Thingies/ - - thing1.py - - thing2.py - - thing3.py - - thing4.py - - ... There's two things I'd like to do here, and I'm not sure how I'm supposed to go about and do them. First, I'd like script1.py and script2.py to be able to get a list of the existing scripts in Module.Thingies, and dynamically import one of them and call functions in it. Second, I want all the scripts in Thingies to be able to import and call functions from script1.py and script2.py. I haven't gotten it to work, though. I tried using dir(Thingies) to get a list of submodules containined within it, but it only works once the entirety of Thingies has been imported, which means prefacing either script1.py or script2.py with 'from Thingies import *'. But whenever I do that, thing?.py will throw an ImportError when I try to have it import either script1.py or script2.py using something like 'from .. import thing1.py'. I think it has something to do with having thing1.py import script1.py that imports thing1.py again, but I don't know how to work around it. What am I supposed to do here to get that to work?
|
# ? Oct 15, 2008 20:02 |
|
GuyGizmo posted:What am I supposed to do here to get that to work? Place an empty text file titled __init__.py in the Thingies folder. For more information look up on python modules and python packages.
|
# ? Oct 15, 2008 20:49 |
|
BlackDiamonds posted:Place an empty text file titled __init__.py in the Thingies folder. For more information look up on python modules and python packages. Actually I did do that already, so it's not the solution here. Also, here's the error specifically that I'm getting: code:
|
# ? Oct 15, 2008 21:26 |
|
GuyGizmo - here's something I used a long time ago - I haven't looked at this recipe since I uploaded it, and I know (knowing as much as I know now) it could be improved. Maybe it helps. http://code.activestate.com/recipes/436873/ drat, that was 3 years and 3 months ago.
|
# ? Oct 15, 2008 21:59 |
|
I think I finally got it. The key seems to be that python just doesn't like circular import statements, so if I load the module I need dynamically it works. I ended up having to do something obtuse like:code:
Thanks for the help everyone.
|
# ? Oct 15, 2008 22:51 |
|
GuyGizmo posted:I think I finally got it. The key seems to be that python just doesn't like circular import statements ... Late to the dance, but this is a point that needs underlining. As opposed to (say) C, where you pay great attention to where and in what order things are included, in Python this _largely_ disappears. I say largely, because circular imports can create all sorts of cryptic errors that are hard to diagnose. The moral: decompose your design properly, so you don't end up with modules calling each other. As for you above problem, I once had to solve something similar and ended up with this: a file (e.g. thing1.py) finds out its own path. Use that to get it's parent directory. List and select the files in that directory. Import doesn't come into it.
|
# ? Oct 16, 2008 11:17 |
|
Trying to get Python Imaging Library working with python on Os/X has got me very loving close to just abandoning developing on macs It shouldnt be this hard, but it is, and the fact that Apples primitive-rear end packaging system (there isnt one) is somewhere around "Slackware in the early 90s" doesnt help at all. Everything on google says to either use fink or macpython. no no no no no I'm not using THAT python, I want to use THIS python that came with it. Argh. Come on Apple, just put one staffer onto maintaining your python distro. Its all it will take! You cant just throw products out the door pre-abandoned. </rant> Seriously Apple should just annoint APT-GET or portage or something and provide official distros of stuff like mysql and the python libs and poo poo, so this primitive rear end nonsense of having to hand patch poo poo all the time to get it to compile is history. God forbid someone wanting to run a mac as a server, and having to deal with security updates to open source software.
|
# ? Oct 16, 2008 12:32 |
|
(Please be kind: I'm normally a perl guy, and just dipping toes in this) Lets say I have a set: [1, 'hi', 38, 'oh hello there'] called ARGL I'm trying to figure out how to do the python version of: OBJECT->method("something", @ARGL) so that OBJECT->method would be called with, effectively: OBJECT->method("something", 1, "hi", 38, "oh hello there") Right now, when I call OBJECT.method("something", ARGL), naturally, it complains, as method() wants more arguments than i'm sending it. I'm missing something blindingly obvious, aren't i?
|
# ? Oct 16, 2008 12:45 |
|
duck monster posted:Trying to get Python Imaging Library working with python on Os/X has got me very loving close to just abandoning developing on macs Adding to the list of "yeah, I had this problem too", you might wants to look at my notes on installing PIL, to see if there is any help there. To be fair, it's not all Apple's fault, the PIL installer is a little odd. Again, image handling is something that should be in the standard library.
|
# ? Oct 16, 2008 12:46 |
|
code:
|
# ? Oct 16, 2008 12:54 |
|
dagard posted:(Please be kind: I'm normally a perl guy, and just dipping toes in this) You mean something like this? EDIT: Should always F5 threads I have had open for a while. code:
|
# ? Oct 16, 2008 13:44 |
|
dagard posted:I'm missing something blindingly obvious, aren't i? http://docs.python.org/tutorial/controlflow.html#unpacking-argument-lists As mentioned already, you can use *foo to unpack the arguments. What hasn't been mentioned is that you can use it in function definitions: code:
|
# ? Oct 16, 2008 14:18 |
|
it may make sense already, but if you're using both the list and dictionary unpack in a function definition, the order is important.code:
I've kind of shied away from dictionary unpacking since programming in python, but your mileage may vary.
|
# ? Oct 16, 2008 14:32 |
|
Lurchington posted:non-alphanumeric catches too much I think. Apostrophe's and commas, parentheses all come up a lot and hurt readability if I nail them. a good way to get rid of random unicode characters while keeping some of their meaning is to use Unicode Normalization, normalize to form KD then strip any unicode character (I use a regex but you can also use .encode('ascii', 'ignore') ). What normal form KD does is decompose a unicode character into it's component characters. So for example ņ becomes n and \x0303 (non-spacing tilde above), when printing they occupy the same space but in the character array they are two indices apart, thus if you run it through a regex it may leave you with only ascii characters. Quick couple lines: code:
|
# ? Oct 17, 2008 06:55 |
|
[st]Newb question, whats the logic behind if __name__ == '__main__'? It seems like some kind of way to test code but I can't quite work it out [/st] cancel that, I've worked it out! LuckySevens fucked around with this message at 09:22 on Oct 17, 2008 |
# ? Oct 17, 2008 09:08 |
|
LuckySevens posted:[st]Newb question, whats the logic behind if __name__ == '__main__'? It seems like some kind of way to test code but I can't quite work it out [/st] Protip: never just say "nm I got it!" -- explain what you found / how you solved your problem! Otherwise another newb finding your question on Google or whatever, and not seeing an actual answer, is going to hate your guts
|
# ? Oct 17, 2008 13:42 |
|
deimos posted:a good way to get rid of random unicode characters while keeping some of their meaning is to use Unicode Normalization, normalize to form KD then strip any unicode character (I use a regex but you can also use .encode('ascii', 'ignore') ). What normal form KD does is decompose a unicode character into it's component characters. So for example ņ becomes n and \x0303 (non-spacing tilde above), when printing they occupy the same space but in the character array they are two indices apart, thus if you run it through a regex it may leave you with only ascii characters. Thanks a lot. This is a much better way of doing it than my previous method.
|
# ? Oct 17, 2008 15:44 |
|
I think I abstracted myself one too many layers with my data class that I made (basically, I want to always interact with it a certain way, but I don't want to always be stuck using shelve). This code fragment will show the contents as staying in the state I initialized it, and neither of the assignment statements I wrote do anything. code:
code:
Thoughts? I get as output: DEBUG: prepped_data = {blah, valid dictionary} DEBUG: inferred_search = "valid string" DEBUG: show contents: {} then a KeyError on logging.debug(self.data[showname][inferred_search]) thanks for any thoughts on this one
|
# ? Oct 17, 2008 20:39 |
|
Is there a way I can get a list of all the objects defined in an import? I'd like to be able to do something like:code:
|
# ? Oct 22, 2008 04:46 |
|
vars(foo_lib) Works on any object except those with __slots__.
|
# ? Oct 22, 2008 05:29 |
|
I'm going to work on making myself a website in python with web.py (didn't like the heavier nature of django all that much), but I'd like to be able to migrate from python 2.5 to 2.6 to then go on 3.0 when/if the framework supports it. I'm currently testing stuff out with apache and mod_wsgi, which needs to be reinstalled anytime you switch version, and googlecode page only talks about support from python 2.3 to 2.5. Am I better off switching to lighttpd? I don't exactly know how switching versions is done there. What would be the best way to do things? Also, what would be the best framework to work with to get fast support for newer versions of python? I do like web.py as stated above and would like to stick with it, but I guess I could go back and try django some more if it fits the needs better.
|
# ? Oct 22, 2008 14:05 |
|
Milde posted:vars(foo_lib) Sorry, I should have written that import line as: code:
edit: I want something similar to sys.modules, except instead of iterating all modules loaded, I want to iterate all classes loaded in a particular module. edit 2: Ah-ha! Checking out vars() got me where I needed to go, though. Here's the code I came up with: code:
SlightlyMadman fucked around with this message at 16:18 on Oct 22, 2008 |
# ? Oct 22, 2008 15:58 |
|
Let's say I have a function and variable defined like thiscode:
basically dynamically constructing the name of my function based on the variable x? I know it can be done in Ruby, but it would make my life a lot easier if Python could do it too.
|
# ? Oct 23, 2008 03:47 |
|
Colorblind Pilot posted:Let's say I have a function and variable defined like this It can be done, but that sort of "clever" programming is generally discouraged because it makes for difficult to debug / understand code (not to mention making bugs a lot more likely). Offhand I'd do it like this: code:
EDIT: Like the below post, I'd say a more transparent and less problem-prone approach would be to explicitly organize the methods in a dict or other data structure, since it's easy to toss around functions as objects. bitprophet fucked around with this message at 04:02 on Oct 23, 2008 |
# ? Oct 23, 2008 03:50 |
|
What are you trying to do? If you're trying to do dispatch based on some kind of input, I'd make a dict mapping strings to functions. If that's too tedious for whatever reason, you could make a lookup function in the same module that uses something like globals()['this_' + x]. If the functions are actually methods, you could use getattr(self, 'this_' + x). I don't know that that's necessarily good style or form though.
|
# ? Oct 23, 2008 03:51 |
|
Milde posted:What are you trying to do? If you're trying to do dispatch based on some kind of input, I'd make a dict mapping strings to functions. How do you make a dict map strings to functions? Milde posted:If the functions are actually methods, you could use getattr(self, 'this_' + x). I don't know that that's necessarily good style or form though Why is that not good style or form? This chapter of Dive Into Python seems to suggest it's fine: http://www.diveintopython.org/power_of_introspection/getattr.html#d0e9362 Colorblind Pilot fucked around with this message at 06:01 on Oct 23, 2008 |
# ? Oct 23, 2008 05:56 |
|
Python supports functions as first-class objects. So one way to do it would be this.code:
|
# ? Oct 23, 2008 06:03 |
|
A better example would be to modify bar() to also take an argument. Usually, if dispatching is through a dictionary functions should have compatible signatures.
|
# ? Oct 23, 2008 06:06 |
|
Yeah, that's true.
|
# ? Oct 23, 2008 07:52 |
|
I often find something like this useful:code:
|
# ? Oct 23, 2008 08:09 |
|
hi i'm learning how to do python. whats the way to do this:code:
|
# ? Oct 23, 2008 11:16 |
|
|
# ? May 23, 2024 17:57 |
|
code:
|
# ? Oct 23, 2008 11:23 |