|
Use virtualenv, it makes using whatever python you like eays.
|
# ? Oct 29, 2010 05:44 |
|
|
# ? Jun 3, 2024 02:25 |
|
I'm just a hobby programmer right now, so I'm curious as to how you more experienced folk are dealing with this: It's really frustrating that all the libraries I want to use don't support Python 3. Should I just stick to Python 2.x for now? I was thinking of learning Python 3 from the get go so I don't have to re-learn all the changes that are made. Advice?
|
# ? Oct 29, 2010 15:41 |
|
king_kilr posted:Use virtualenv, it makes using whatever python you like eays. That doesn't solve the problem he was asking. You use virtualenv to isolate a set of modules from the set installed on the system. You need to put the directory containing your custom Python build at the beginning of your PATH environment variable, or at the very least, ahead of any other directories containing Python binaries. Then, your shebangs should be: code:
|
# ? Oct 29, 2010 16:30 |
|
Bodhi Tea posted:I'm just a hobby programmer right now, so I'm curious as to how you more experienced folk are dealing with this: which libraries are giving you a problem? python3 is worth using if you're going to have to deal with unicode, beyond that 2.7 is pretty comparable to 3.2 so uh, learn whatever - the differences aren't big between them.
|
# ? Oct 29, 2010 17:50 |
|
I have a minor curiosity. I sometimes use this class in various testing apps -- it basically walks an n-dimensional integer space. Put another way, it encodes n nested for loops in one. The list it produces can be indexed directly, so it makes it easy to say "re-run test 57", which is the test whose parameters are [1,4,7,5] or whatever. Code:code:
|
# ? Oct 29, 2010 20:02 |
|
MaberMK posted:That doesn't solve the problem he was asking. You use virtualenv to isolate a set of modules from the set installed on the system. My point was you can use any Python to create a virtualenv, and then it's easy to ensure you're using the right Python (and assosciated modules) by simply ensuring you're in the right venv.
|
# ? Oct 29, 2010 21:11 |
|
Stabby McDamage posted:I have a minor curiosity. I sometimes use this class in various testing apps -- it basically walks an n-dimensional integer spa itertools is your friend code:
|
# ? Oct 29, 2010 23:20 |
|
tef posted:itertools is your friend Wow, that's crazy. Very cool. One thing though -- I need to be able to subscript the object without building the whole thing in memory. This generator would need to iterate up to the index. Any ideas on how to encode my math-based algorithm using similar magic?
|
# ? Oct 30, 2010 04:20 |
|
I don't get it, where in that code does anything get built up in memory entirely? Product gives you an iterator and xrange doesn't store the whole list in memory at once like range does.
|
# ? Oct 30, 2010 05:05 |
|
Let me clarify: if I want to jump directly to an index, I need to walk through it. I can do that either by iterating it to a point and then stopping (large time cost per lookup) or building the whole thing in memory and accessing it like a list (initial time cost + large memory cost). The class I posted can be used as an iterator or as a direct look-up without paying either of these overheads.
|
# ? Oct 30, 2010 13:14 |
|
Another newbie! Ive been trying to learn Python here and there for the last 3 years, on and off. I always get suck at dictionaries. Ill be in school for Computer Science soon, but gently caress, I want some programming action now. Anyway, Im gonna try my hand at this again now that the urge to learn has come back again. I'll be back often to bug everyone. Remember me, Ill be the dumbass.
|
# ? Nov 1, 2010 10:49 |
|
Three dumb questions: 1. What is the easiest way to turn a generator into a list? I was playing with itertools on the command line, and of course when I do "product('abc')", all I see is "<itertools.product object at 0x1e21140>". I've been wrapping these generators with "[x for x in <whatever>]", but I'm thinking there's got to be some shorthand for that. 2. Is there any way to ask for the old print statement in python 3? I'd never use it in code, but it might be nice on the command line. Unfortunately, it doesn't look like there's a "__past__" module. 3. I just noticed that I can chain comparators and it seems to do the correct (mathematical) thing. This conflicts with my expectation that operators of equal weight are evaluated left-to-right. For example: pre:a=2 I type: 3 < a < 6 I expect: (3 < a) < 6 → (False) < 6 → True # mathematically stupid, but matches behavior of C, Java, Perl, etc. I get: 3<a and a<6 → False and True → False # mathematically sound, useful syntax, but differs from programmer expectation. Stabby McDamage fucked around with this message at 18:35 on Nov 1, 2010 |
# ? Nov 1, 2010 18:25 |
|
Stabby McDamage posted:1. What is the easiest way to turn a generator into a list? I was playing with itertools on the command line, and of course when I do "product('abc')", all I see is "<itertools.product object at 0x1e21140>". I've been wrapping these generators with "[x for x in <whatever>]", but I'm thinking there's got to be some shorthand for that.
|
# ? Nov 1, 2010 18:35 |
|
Threep posted:You're probably going to slap yourself now: list(product('abc')) I knew it had to be something that simple. I should have thought of that.
|
# ? Nov 1, 2010 18:37 |
|
There's no __past__, or any other way to restore the print statement. Chained comperators are quiet intentional, there aren't really any gotchas, unless you consider: code:
|
# ? Nov 1, 2010 19:14 |
|
king_kilr posted:There's no __past__, or any other way to restore the print statement. Is there a document that explains this feature in greater depth? I'm curious what the precise algorithm for doing this is, since it violates my expectation that everything is always evaluated left-to-right.
|
# ? Nov 1, 2010 23:09 |
|
It is still evaluated left to right:code:
|
# ? Nov 2, 2010 00:12 |
|
So I'm used to Perl, and being able to run my scripts under perl -d to throw it into a step-by-step debug mode where I can check and set values and such. Is there any way to do this in Python? IDLE is nice to test ideas out line by line, but running a script within it just seems to run python as normal, with no stepping through line/into functions etc, and I'm not even certain how to check/set values of variables. Any clues?
|
# ? Nov 2, 2010 02:50 |
|
Rohaq posted:So I'm used to Perl, and being able to run my scripts under perl -d to throw it into a step-by-step debug mode where I can check and set values and such. Is there any way to do this in Python? IDLE is nice to test ideas out line by line, but running a script within it just seems to run python as normal, with no stepping through line/into functions etc, and I'm not even certain how to check/set values of variables. http://docs.python.org/library/pdb.html
|
# ? Nov 2, 2010 03:06 |
|
Huh, Sikuli looks pretty cool for automating GUI's with Python.
|
# ? Nov 2, 2010 04:24 |
|
BeefofAges posted:http://docs.python.org/library/pdb.html
|
# ? Nov 2, 2010 13:47 |
|
Could anyone tell me if there is a way to prevent python (2.6.5) appending an 'L' to long numbers? For example I have a django view function that multitplies a unix timestamp by 1000 to give a javascript timestamp. The page loads correctly via a webserver but python returns a 'long' number with an L on the end (for example 20991600000L) which breaks the javascript. I havent been using python for long, so sorry if this is something obvious. I've had a quick read around the documentation, but cant really see an answer (other than maybe increase sys.maxint?). Maccers fucked around with this message at 23:24 on Nov 2, 2010 |
# ? Nov 2, 2010 23:16 |
|
Maccers posted:Could anyone tell me if there is a way to prevent python (2.6.5) appending an 'L' to long numbers? code:
|
# ? Nov 2, 2010 23:34 |
|
Maccers posted:Could anyone tell me if there is a way to prevent python (2.6.5) appending an 'L' to long numbers? code:
|
# ? Nov 2, 2010 23:35 |
|
Rohaq posted:The -m pdb argument was exactly what I was looking for. I can't see much in setting conditional breakpoints though; I've only got breaking on lines or functions at the moment. Can you get pdb to break on a condition? Put this in your code: code:
|
# ? Nov 3, 2010 03:01 |
|
Maccers posted:Could anyone tell me if there is a way to prevent python (2.6.5) appending an 'L' to long numbers? Your question has already been answered, but as a point of interest, that format you see is what is produced by the repr function. Repr is a builtin and also a method defined on all objects (invoking the builtin repr on an object will call the matching double underscore method defined on that class). Repr (which im guessing means reproduce) is mostly intended for representing objects in such a manner that they can be reconstructed, ideally by just throwing the result of repr into a call to eval. Compare this to the str function, which is used more for the purpose of representing objects in a compact and legible way; str doesn't care about making it reproduce the original object when you throw it into eval. In python, integer values can either be of type int (which is really a c long) or long (which is arbitrary precision). To explicitly specify an integer as being a long in python code, you can suffix it with L. Accordingly, repr on longs will always have the L tacked on, because the expectation is that calling eval(repr(somelong)) will yield a value of the same type as "somelong". I'm not sure how you are accessing this number from your application but if your data is ending up on a webpage then its a given that its getting converted to a string at some point. Its bizarre then that you see an L at the end of your number, since that would probably only result from calling repr on a long integer. Only I'm not sure why repr would be called on it if you didn't do it explicitly. As far as I'm aware, repr will get called if you surround an object in backticks (`) or if you are using python in interactive mode and just executing statements consisting of a variable name. tripwire fucked around with this message at 03:37 on Nov 3, 2010 |
# ? Nov 3, 2010 03:33 |
|
tripwire posted:I'm not sure how you are accessing this number from your application but if your data is ending up on a webpage then its a given that its getting converted to a string at some point. Its bizarre then that you see an L at the end of your number, since that would probably only result from calling repr on a long integer. Only I'm not sure why repr would be called on it if you didn't do it explicitly. As far as I'm aware, repr will get called if you surround an object in backticks (`) or if you are using python in interactive mode and just executing statements consisting of a variable name. Maccers: if you are using string formatting to build JavaScript variable definitions, stop that. Use JSON (via standard library module json).
|
# ? Nov 3, 2010 04:14 |
|
tripwire posted:Repr (which im guessing means reproduce) is mostly intended for representing objects in such a manner that they can be reconstructed representation
|
# ? Nov 3, 2010 05:08 |
|
Thanks for the assistance guys - got it working using a string rather than number type. Janin: Yeah I was, I'll take a look at using JSON as a longterm solution.
|
# ? Nov 3, 2010 20:07 |
|
Maccers posted:Janin: Yeah I was, I'll take a look at using JSON as a longterm solution. code:
code:
|
# ? Nov 3, 2010 20:54 |
|
I'm pretty brand spanking new to coding, and I'm trying to learn the logic of coding along with syntax of it (Python in particular). I was looking for videos for Python that could help me get a grasp on the language, but failing that I just started to read the documentation, word for word, going along and doing everything it does and I've gotten as far as "4. More Control Flow Tools". And I'm just wondering if this is the wrong way to try to learn it, because none of this seems to be sticking in my head longer than 5 minutes, and I have to go back and look to remember parts. I've just been trying to teach myself how to use it, and I'm not actually learning anything.
|
# ? Nov 4, 2010 02:35 |
|
Ularg posted:I'm pretty brand spanking new to coding, and I'm trying to learn the logic of coding along with syntax of it (Python in particular). I was looking for videos for Python that could help me get a grasp on the language, but failing that I just started to read the documentation, word for word, going along and doing everything it does and I've gotten as far as "4. More Control Flow Tools". And I'm just wondering if this is the wrong way to try to learn it, because none of this seems to be sticking in my head longer than 5 minutes, and I have to go back and look to remember parts. I've just been trying to teach myself how to use it, and I'm not actually learning anything. You will learn the syntax over time through repetition. I've been programming for a lot longer than you have and I still need to refer to the docs whenever I use some essoteric part of the syntax. The only benefit is that now I know what part of the docs to look at.
|
# ? Nov 4, 2010 02:44 |
|
I'm hoping to use the matplotlib toolkit Basemap as a lightweight prototyping environment for some parts of an ArcGIS tool I'm putting together, but when I try code:
I'm running XP64, Python 2.6.2. The python install is all 32bit. "more information about this error" only gives: code:
code:
I can't find any info online about anyone having the same issue. Any ideas?
|
# ? Nov 4, 2010 03:27 |
|
Ularg posted:I'm pretty brand spanking new to coding, and I'm trying to learn the logic of coding along with syntax of it (Python in particular). I was looking for videos for Python that could help me get a grasp on the language, but failing that I just started to read the documentation, word for word, going along and doing everything it does and I've gotten as far as "4. More Control Flow Tools". And I'm just wondering if this is the wrong way to try to learn it, because none of this seems to be sticking in my head longer than 5 minutes, and I have to go back and look to remember parts. I've just been trying to teach myself how to use it, and I'm not actually learning anything.
|
# ? Nov 4, 2010 05:58 |
|
Spatial posted:I think these MIT comp-sci lectures would be a good place to start. The class focuses on teaching the essentials of programming, using Python's interactive shell to demonstrate the concepts. Use the shell to play with the concepts as you go along, you'll learn a lot. This is a godsend, thank you.
|
# ? Nov 4, 2010 06:20 |
|
Spime Wrangler posted:I can't find any info online about anyone having the same issue. Any ideas? If Python is just crashing without even printing a stack trace, I'm guessing it might be an interpreter bug. Try with 2.6.6 maybe and see if there's the same issue?
|
# ? Nov 4, 2010 06:49 |
|
Heh, guess I haven't updated for some time now. Its working fine at home under 2.6.6 so nvm I guess.
|
# ? Nov 4, 2010 07:35 |
|
tripwire posted:Put this in your code: code:
|
# ? Nov 4, 2010 13:29 |
|
Rohaq posted:Is there no easier way to do this on the fly from within the Pdb console? In Perl, I could just type What tripwire is saying is that python will start an interactive debugging session when you get to that condition. You can of course set conditional breakpoints inside pdb (or if you prefer, ipdb) using pretty much the same exact syntax as perl's debugger. pdb documentation lives here.
|
# ? Nov 4, 2010 15:15 |
|
|
# ? Jun 3, 2024 02:25 |
|
This feels wrong to me:code:
code:
It can be "hours" or "hour" If it doesn't reach hours or minutes then it will only contain up to minutes or seconds, respectively.
|
# ? Nov 4, 2010 23:52 |