![]() |
|
Re: ** Python Support Thread **
Quote:
And this is coming from someone that uses Print statements way too often. |
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
After messing with it a bit, I figured out that I can develop .py files and then execute them directly from the cmd line. Simple!
|
Re: ** Python Support Thread **
Quote:
|
Re: ** Python Support Thread **
Quote:
I do agree that an IDE is not critical though, but it can be convenient. I prefer Emacs, but I also use an IDE too. Wing IDE is a Python specific IDE that's free for non-commercial purposes. It doesn't have any overhead to setting it up (unlike Eclipse), so it can be good for beginners. And Eclipse has already been mentioned. |
Re: ** Python Support Thread **
What type of debugger do you use with Python? Is there a program that will allow you to step through instructions and inspect values along the way?
|
Re: ** Python Support Thread **
http://docs.python.org/library/pdb.html
My most common use case is just sticking: import pdb pdb.set_trace() wherever I want to jump into the code. |
Re: ** Python Support Thread **
ok am i losing my mind, or is this behavior just absurdly ******ed?
(yes, i appreciate the irony of my printf debugging considering the above discussion, but i'm trying to demonstrate a point.) Code:
Spoiler:
is there some simple workaround to this problem? do i need to make a separate clone of list for purposes of iterating? ugh, python. |
Re: ** Python Support Thread **
Messing with a list while you iterate through it is generally a bad idea, and that's not python-specific.
|
Re: ** Python Support Thread **
i mean, sure, i guess. i guess i don't know enough about how python handles its iterators internally to have an expectation that this would work.
that said, i feel like this pattern works fine in other languages. maybe i'm just losing my mind, as alluded to in my previous post :). edit: adding list_copy = copy.deepcopy(list) and iterating on that seems to solve the problem. i think the real solution is to use map/apply/whatever-the-****-python-calls-it with a lambda or small function, but i don't think it will greatly improve efficiency and it will probably hurt readability. |
Re: ** Python Support Thread **
Quote:
Edit: And yes, you probably just want: filter(lambda x: type(x) == int, list) Edit again: I'd consider this more readable. But that's pretty subjective. Especially since lots of stuff is considered readable by regular python users that isn't readable by people not use to it. |
Re: ** Python Support Thread **
Quote:
so something like: Code:
list = [el for el in list if type(el) == int]So maybe something like Code:
def convertable(x): |
Re: ** Python Support Thread **
Quote:
Quote:
"is not None" is another of those python things i feel i will never get used to. Quote:
|
Re: ** Python Support Thread **
except I got it wrong, of course! I made a typo and a bad error.
because you need to be able to cast other things to integers, it needs to behave like Code:
def convertable(x): |
Re: ** Python Support Thread **
Has anyone here used the C API? I'm having trouble calling a C function from another C function.
|
Re: ** Python Support Thread **
maybe just post some code and see if anyone bites?
|
Re: ** Python Support Thread **
Ok then. I've used the C API a lot before, and it's basically coding in C with a little gymnastics to pass values between C and python. I'm doing some project euler now to brush up on those skills now while I'm unemployed.
So this function takes int n and returns a list of all the factors of n (it's not complete yet, just the relevant code that's spitting out errors is here). isPrime returns True or False. I'm trying to check if n is prime before I try to factor it. Code:
static PyObject *Code:
static PyObject *Code:
res = PyEval_CallFunction(euler_isPrime, "i", n);Code:
euler.c:71: warning: passing argument 1 of ‘PyEval_CallFunction’ from incompatible pointer type |
Re: ** Python Support Thread **
no experience with c->python but i'll take a stab:
do you need to instantiate euler_isPrime before you use it? it's not clear to me where that value is coming from. i also don't understand what you're doing with the long i and why you pass "i" to PyEval_CallFunction. perhaps all of this is just my ignorance of the api. if so, at least we have quickly weeded out any advice i might give on this problem as useful. edit: also did you look at ceval.h line 21 to see if that gave you any clue what was going on? |
Re: ** Python Support Thread **
Quote:
Quote:
Quote:
|
Re: ** Python Support Thread **
This reminds me that I shouldn't have put C on my resume.
|
Re: ** Python Support Thread **
Quote:
That being said, I'd actually combine answers and define the function and put that in the filter method. So: Quote:
|
Re: ** Python Support Thread **
Quote:
Code:
list = [int(x) for x in list if x.isdigit()] |
Re: ** Python Support Thread **
That doesn't work since you can't call isdigit on an integer.
|
Re: ** Python Support Thread **
Quote:
Code:
[x for x in list if type(x) is int] |
Re: ** Python Support Thread **
Do people feel the list comprehension is better than using filter here? Seems weird to me.
|
| All times are GMT -4. The time now is 12:19 PM. |
|
Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright © 2008-2020, Two Plus Two Interactive