User Profile
Collapse
-
hey thanks for breaking it up onto many lines, i'm so fresh at this that when it's all squeezed into one line my mind breaks -
that works well, but i'm trying to keep a blank line if the '\n' was there to begin with, how can i tweak that so the solution would have been
'16\n\n54\n18\n 17\n18\n18'
thanksLeave a comment:
-
converting to an integer
hey everyone, i'm having a mental block can anyone help me out
if i have a list like this
num = ['1;3;2;3;2;1;4' , '\n', '30;2;13;2;1;4; 2', '2;3;2;1;4;2;4' , '3;2;1;4;2;4;1' , '2;1;4;2;4;1;4' , '1;4;2;4;1;4;2']
how might i get python to recognize each elemant as an integer so that i can sum each list
that is have it print
16
\n
54
18
etc
tha... -
Or, if i'm not mistaken, you could just take the string you get from raw_imput and turn that into an integer.
(this code has not be tested and i am a rookie, so there could be an error)...
username_string = raw_input("Ente r your usernamer: ")
unsername_integ er = int(username_st ring)
this way you can computer numbers to numbers rather than text to numbers.Leave a comment:
-
regex matching
if i have a string, let's say its
xx = 'abc123def456gh i"
i'm having problems figuring out a way to know if xx[0] is a letter or number, then check xx[1] for the same thing and so on and so forth.
what i thought would be easiest is doing somethign through regex
have
pattern1 = re.compile('[a-z]')
pattern2 = re.compile('[0-9]')
can i make a loop that check something... -
regex + string formatting?
Can I regex (dont know if that's truely a verb, but i digress...) in string functions such as split, replace or strip?
What i want to do is with a file that has lines like
asd5Jkl;lk
132bn8K;lk
I want to split them whenever i have a number followed by a capital letter.
I immediatly thought usinng regex and somehing like pattern = "[0-9][A-Z]"
Ideally i'd split... -
logic question
i'm having a mental block with logic statements...
if i want to say something like
"if a or b or c, the do X, else if d or e do Y"
what's the syntax for getting the OR in, because just or doesn't seem to do it -
exuse my ignorance, can anyone help me understand what this is doing. I'll write out the extent of my grasp...
s = ''.join(['%s' % ([str(item)+',', str(item)+'\n'][not (i+1)%step or 0]) \
for i, item in enumerate(data)
])
''.join(list) <--- makes a list into a string
%s <--- refers to a latered reference string as in
x = "pizza"...Leave a comment:
-
formatting written data
hey everyone,
if i have a list (or string) like this
data = [1,2,3,4,5,6,7,8 ,9,10,11,12,13, 14,15]
and i wanted to write it to my file (lets say its called fn) so that i appears like this with 5 points per row
1,2,3,4,5
6,7,8,9,10
11,12,13,14,15
how much I got about that? I'm begginign to understand how to do it just as a print option in the python interpreter... -
max() error
I've gotten this exact problem before and I was able to once figure it out. Since then i've apparently forgetten more of the basic.
Does anyone have any idea whats going on here, because fdayhigh is not an empty list...
Code:>>> import justCup Traceback (most recent call last): File "<interactive input>", line 1, in <module> File "justCup.py", line 63, in <module>
-
so i broke it down and did a small test and it worked, meaning there must be something funny w/ my script/logic....we'll be revisiting this subject soon, hopefully someone will be willing to help if i need it later...Leave a comment:
-
So is reload not actually equivalent to closing somethign like PythonWin then reopening and importing again?
Because if i do the long process it notices changes made in the text file that my script draws from. If i do a reload it doesn't....
any ideas how i can get it to recognize changes i' ve made in the text file that a script reads from w/o close and reopening PythonWin?
thanks...Leave a comment:
-
using reload(module)
Someone suggested I use reload when trying to reopen a script i've written (the suggestion was made in response to the problem ive reposted below)
however when i do reload(modolena me) i only get this...
Code:>>> reload(eps) <module 'eps' from 'eps.pyc'>
-
importing scripts
When I'm testing a script in PythonWin after I import it once, it won't recognize some changes i've made sometimes. Like if its a script to do a web scrape...
the 1st time i try import testscript, it'll take the couple of seconds that is needed to do the scrape. thats good.
Then lets say i change a part of the scrape. For example one thing i often do is have a text file where i have names. My script will take a name out of the... -
comparing data
hey everyone,
i'm going to be comparing data in a list. Just basic >= or <= type stuff.
However, the list i have somtimes starts with 'n/a'. That is somtimes it starts like this:
data = ['1.0', '2.0', '1.5']
or
data = ['n/a', '1.0', '2.0', '1.5']
or
data = ['n/a', 'n/a', '1.0', '2.0', '1.5']
so i thought i could do something like this. so that I can start... -
When I try your method I get an error that is like this...
Code:>>> s = f.next() Traceback (most recent call last): File "<interactive input>", line 1, in <module> StopIteration >>>
ThanksLeave a comment:
-
scraping question
hey everyone, here's probably an easy qu but i'm new to this...
i'm doing a web scrabe and the line i want in the source code looks like this:
Code:<td>Return on Average Equity</td> <td align=right> 16.08% </td> <td align=right> 10.58% </td> <td align=right> 11.71% </td>
-
enumerate vs while
Sorry for the simplicity of my questions, but is enumerate a way around using while loops
my while loop is this:
Code:x = 1 >>> while x < len(rate): ... try: ... growth.append(rate[x]) ... x += 3 ... except IndexError: ... break ...
-
try/except within a while loop problem
Hey,
If i use a try/except clause to get around something like a TypeError, will that immediately bust me out of a while loop?
If so, is there any way i can tell it to stay in the while loop until its completed.
here's what I'm doing:
Code:>>> stuff2 ['0.53', '0.36', 'n/a', '0.45', '0.60'] >>> aa = 0 >>> bb = 1 >>> sub = []
-
Ignore that, i forgot that stuff2 is still a string, if i still am having a problem, i'll put another post up.
thanksLeave a comment:
No activity results to display
Show More
Leave a comment: