User Profile

Collapse

Profile Sidebar

Collapse
Patrick C
Patrick C
Last Activity: Mar 28 '08, 10:36 PM
Joined: Apr 5 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Patrick C
    replied to converting to an integer
    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
    See more | Go to post

    Leave a comment:


  • Patrick C
    replied to converting to an integer
    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'

    thanks
    See more | Go to post

    Leave a comment:


  • Patrick C
    started a topic converting to an integer

    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...
    See more | Go to post

  • Patrick C
    replied to Log in and password
    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.
    See more | Go to post

    Leave a comment:


  • Patrick C
    started a topic regex matching

    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...
    See more | Go to post

  • Patrick C
    started a topic regex + string formatting?

    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...
    See more | Go to post

  • Patrick C
    started a topic logic question

    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
    See more | Go to post

  • Patrick C
    replied to formatting written data
    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"...
    See more | Go to post

    Leave a comment:


  • Patrick C
    started a topic formatting written data

    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...
    See more | Go to post

  • Patrick C
    started a topic max() error

    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>
    ...
    See more | Go to post

  • Patrick C
    replied to using reload(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...
    See more | Go to post

    Leave a comment:


  • Patrick C
    replied to using reload(module)
    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...
    See more | Go to post

    Leave a comment:


  • Patrick C
    started a topic using reload(module)

    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'>
    i know this is incredibly amateur to say, but the person who suggested it had their reload bolded and in color, as if it was recognized...
    See more | Go to post

  • Patrick C
    started a topic importing scripts

    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...
    See more | Go to post

  • Patrick C
    started a topic comparing data

    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...
    See more | Go to post

  • Patrick C
    replied to scraping question
    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
    >>>
    Also, if i plan to do this a few hundred/thousand times...would I need to create a few hundred/thousand text.txt files before hand?

    Thanks
    See more | Go to post

    Leave a comment:


  • Patrick C
    started a topic scraping question

    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>
    The number i want to get out...
    See more | Go to post

  • Patrick C
    started a topic enumerate vs while

    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
    ...
    thanks
    See more | Go to post

  • Patrick C
    started a topic try/except within a while loop problem

    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 = []
    ...
    See more | Go to post

  • Patrick C
    replied to handling python errors
    Ignore that, i forgot that stuff2 is still a string, if i still am having a problem, i'll put another post up.

    thanks
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...