Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
BigRedDot
Mar 6, 2008

OnceIWasAnOstrich posted:

Alternatively if you want to build the package as normal use pip anyway.
You can also build your own conda packages, and distribute them through your own server, or through http://binstar.org Have seen folks do this to good effect for setting up a TravisCI testing environment, for example.

Adbot
ADBOT LOVES YOU

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
So once I get my conda environment setup locally, how do you get the configuration in version control and then deploy out to production machines?

Symbolic Butt
Mar 22, 2009

(_!_)
Buglord

Brennan posted:

I just worked through Learning Python by Lutz and feel like I have a decent beginners level grasp of the language. I'm learning because I'm in a computer forensics program, and it's a good skill to have in the field but the program doesn't really touch on it. Are there any recommendations of newbie friendly places where I might be able to contribute and it would let me practice and learn through doing? I'm willing to put in the time, I'm just hoping for some direction.

I don't know much about computer foresincs but I have an interest in it. If material can help you, I really like this basic intro to NLP by Peter Norvig: http://nbviewer.ipython.org/url/norvig.com/ipython/How%20to%20Do%20Things%20with%20Words.ipynb

edit: duh I was thinking of foresinc linguistics :doh:

Symbolic Butt fucked around with this message at 21:43 on Apr 25, 2014

BigRedDot
Mar 6, 2008

fletcher posted:

So once I get my conda environment setup locally, how do you get the configuration in version control and then deploy out to production machines?

conda list -e will spit out an environments contents in a way that conda install --file <file> can use to recreate.

code:
bryan@laptop  ~ $ conda create -n myenv python=3 numpy scipy pandas
Fetching package metadata: ..
Solving package specifications: ....
Package plan for installation in environment /Users/bryan/anaconda/envs/myenv:

The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    setuptools-3.4.4           |           py34_0         470 KB

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    dateutil-2.1               |           py34_2   hard-link
    numpy-1.8.1                |           py34_0   hard-link
    openssl-1.0.1g             |                0   hard-link
    pandas-0.13.1              |       np18py34_0   hard-link
    python-3.4.0               |                0   hard-link
    pytz-2014.2                |           py34_0   hard-link
    readline-6.2               |                2   hard-link
    scipy-0.13.3               |       np18py34_0   hard-link
    setuptools-3.4.4           |           py34_0   hard-link
    six-1.6.1                  |           py34_0   hard-link
    sqlite-3.8.4.1             |                0   hard-link
    tk-8.5.13                  |                1   hard-link
    zlib-1.2.7                 |                1   hard-link

Proceed ([y]/n)? 

Fetching packages ...
setuptools-3.4.4-py34_0.tar.bz2 100% |###########################################################################| Time: 0:00:01 396.64 kB/s
Extracting packages ...
[      COMPLETE      ] |##############################################################################################################| 100%
Linking packages ...
[      COMPLETE      ] |##############################################################################################################| 100%
#
# To activate this environment, use:
# $ source activate myenv
#
# To deactivate this environment, use:
# $ source deactivate
#
bryan@laptop  ~ $ conda list -n myenv -e > /tmp/myenv
bryan@laptop  ~ $ conda create -n myenv2 --file /tmp/myenv 
Fetching package metadata: ..
Solving package specifications: 
Package plan for installation in environment /Users/bryan/anaconda/envs/myenv2:

The following packages will be linked:

    package                    |            build
    ---------------------------|-----------------
    dateutil-2.1               |           py34_2   hard-link
    numpy-1.8.1                |           py34_0   hard-link
    openssl-1.0.1g             |                0   hard-link
    pandas-0.13.1              |       np18py34_0   hard-link
    python-3.4.0               |                0   hard-link
    pytz-2014.2                |           py34_0   hard-link
    readline-6.2               |                2   hard-link
    scipy-0.13.3               |       np18py34_0   hard-link
    setuptools-3.4.4           |           py34_0   hard-link
    six-1.6.1                  |           py34_0   hard-link
    sqlite-3.8.4.1             |                0   hard-link
    tk-8.5.13                  |                1   hard-link
    zlib-1.2.7                 |                1   hard-link

Proceed ([y]/n)? 

Linking packages ...
[      COMPLETE      ] |##############################################################################################################| 100%
#
# To activate this environment, use:
# $ source activate myenv2
#
# To deactivate this environment, use:
# $ source deactivate
#

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Looks pretty cool! I'm gonna play around with this today. Thanks for the examples!

edit: Oh also, is my IDE (PyCharm) gonna freak out if I'm not using virtualenv anymore?

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

fletcher posted:

Looks pretty cool! I'm gonna play around with this today. Thanks for the examples!

edit: Oh also, is my IDE (PyCharm) gonna freak out if I'm not using virtualenv anymore?

No, you just point it to the right interpreter.

Nippashish
Nov 2, 2005

Let me see you dance!

BigRedDot posted:

Yah that was an early decision, we wanted simple named environments but also didn't want to have to introduce a persistence layer to map those names to absolute paths. conda started out as just a devops tool for us, if I'd known how popular it would become I probably would have made a different decision. Still I can imagine it would not be to difficult to add this kind of behavior: source activate -r <relpath> or something similar. I'll mention this to Aaorn and Ilan but the best way is to make a GH issue (https://github.com/conda/conda) or ask about it on the mailing list. (Edit: or even better a Pull Request!)

More Edit: I think source activate ./myenv should work too?

I did ask on github a while ago but I don't think it's high on anyone's priority list (it's not high on mine either, since I've got my own scripts around conda at this point). It is nice that source activate ./myenv works though. I remember trying this back when I started using conda and back then it would just add ./myenv to my path which obviously doesn't work if you change to a different working directory. This seems to be fixed though.

YouTuber
Jul 31, 2004

by FactsAreUseless
I was learning Python earlier through the Google classes but I had to drop it since stuff came up. During those courses it told you to indent 2 spaces but this CodeAcademy site that I got recommended is telling me to do 4. What is the most accepted way to indent? Both are functional, two seems functional enough to catch my eye for debugging purposes.

SurgicalOntologist
Jun 17, 2004

That's weird, the Google style guide says 4 spaces:
http://google-styleguide.googlecode.com/svn/trunk/pyguide.html#Indentation

Scaevolus
Apr 16, 2007

YouTuber posted:

I was learning Python earlier through the Google classes but I had to drop it since stuff came up. During those courses it told you to indent 2 spaces but this CodeAcademy site that I got recommended is telling me to do 4. What is the most accepted way to indent? Both are functional, two seems functional enough to catch my eye for debugging purposes.

PEP8 is the canonical Python style guide, and it specifies 4 spaces.

Most Python code you'll find has 4-space indents.

YouTuber
Jul 31, 2004

by FactsAreUseless

https://www.youtube.com/watch?v=tKTZoB2Vjuk

Their supplementary video uses two and he states the google standard is two as well. I'll just use 4 if that is what the majority of people use.

Dominoes
Sep 20, 2007

YouTuber posted:

Their supplementary video uses two and he states the google standard is two as well. I'll just use 4 if that is what the majority of people use.
Like Scaev said, the official documentation for this type of thing is PEP 8. Follow it until you understand it, and have a reason to deviate.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

I deviate from PEP8 on that, though if I'm sharing code with the wider world I just convert to 4 spaces.

Personally, I like tabs for indentation and spaces for lining stuff up. That way people can set tabs to whatever width they want and things I want to stay aligned do so because I used spaces.

The important thing to do, especially for beginners, is to stay consistent and a good way to stay consistent is to have a formal written guide, and PEP8 is great for that.

QuarkJets
Sep 8, 2008

I like the look of 4 spaces, 2 spaces barely looks different from 1

Dren
Jan 5, 2001

Pillbug
pycharm's emacs emulation is really thorough, is there a way to get the emacs cua-mode?

I can't seem to find an IDE that doesn't implement column select mode without some sort of poo poo mouse selection instead of the totally great ctrl+enter thing that cua-mode does.

lufty
Jan 26, 2014
Python code:
#Encounter Outcome Program
import random #imports the random feature, allows randomisation of given values

def CharAttr():
    CharName1 = input("What is your first character's name?\n")
    CharStr1 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl1 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharName2 = input("What is your second character's name?\n")
    CharStr2 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr2 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl2 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl2 < 1:
        print("Invalid Input.")
        CharAttr()

StrengthMod = abs(CharStr1 - CharStr2)//5
SkillMod = abs(CharSkl1 - CharSkl2)//5
CharDice1 = random.randint(1, 6) #dice
CharDice2 = random.randint(1, 6) #rolls

if CharDice1 > CharDice2: #first character wins
        CharStr1 = CharStr1 + StrengthMod
        CharSkl1 = CharSkl1 + SkillMod
        CharStr2 = CharStr2 - StrengthMod
        CharSkl2 = CharSkl2 - SkillMod

elif CharDice1 < CharDice2: #second character wins
        CharStr1 = CharStr1 - StrengthMod
        CharSkl1 = CharSkl1 - SkillMod
        CharStr2 = CharStr2 + StrengthMod
        CharSkl2 = CharSkl2 + SkillMod
else:
    print("The Characters were too evenly matched, therefore no encounter occurred!")
    exit(0) #exits if draw occurs

if CharSkl1 < 1:
    CharSkl1 = 0

elif CharSkl2 < 1:
    CharSkl2 = 0

if CharStr1 < 1:
    print(CharName1, "is now dead")

elif CharStr2 < 1:
    print(CharName2, "is now dead")

if CharStr1 and CharStr2 and CharSkl1 and CharSkl2 > 0:
    print(CharName1, "ended the fight with a Strength of", CharStr1, "and a Skill of", CharSkl1)
    print(CharName2, "ended the fight with a Strength of", CharStr2, "and a Skill of", CharSkl2)
    if CharStr1 and CharSkl1 > CharStr2 and CharSkl2:
        print(CharName1, "won!\n")
        print("The program has now finished")
        exit(0)
    elif CharStr2 and CharSkl2 > CharStr1 and CharSkl1:
        print(CharName2, "won!\n")
        print("The program has now finished")
        exit(0)
    else: 
        print("The program has now finished")
        exit(0)
any idea why I'm getting this traceback error?

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
You never assigned anything to CharStr1.

lufty
Jan 26, 2014

Suspicious Dish posted:

You never assigned anything to CharStr1.

I assigned input right?

also, forgive me for this little thing lol

Crosscontaminant
Jan 18, 2007

You never call CharAttr, and even if you did CharStr1 is only declared inside its scope (as are many other things) so once execution leaves the function all those definitions go kaput.

e: also recursing functions is generally a poor idea in Python - in this example I can fill your call stack by repeatedly providing invalid input.

Lyon
Apr 17, 2003

Suspicious Dish posted:

You never assigned anything to CharStr1.

To add a little bit to this, your indenting and/or logic appears to be off. You have a function called CharAttr() but that functions ends after the last indented elif statement.

Python code:
def CharAttr():
    CharName1 = input("What is your first character's name?\n")
    CharStr1 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl1 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharName2 = input("What is your second character's name?\n")
    CharStr2 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr2 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl2 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl2 < 1:
        print("Invalid Input.")
        CharAttr()
All the variables that fall under CharAttr() are local to the function itself (only accessible within CharAttr()), not the entire program.

You have three options:
  1. Include the rest of your code under the CharAttr() function by indenting all of the lines
  2. Return the values from the CharAttr() function back to the __main__ part of the program (you could return dict with key/value pairs, a character class, a list, a tuple, whatever) and create new variables in the __main__ part of your program to assign these values to.
  3. Make these variables global (don't kill me thread) by instantiating them at the top of your program and then using the global keyword within your CharAttr() and __main__ functions.

Lyon fucked around with this message at 20:02 on Apr 29, 2014

lufty
Jan 26, 2014

Lyon posted:

To add a little bit to this, your indenting and/or logic appears to be off. You have a function called CharAttr() but that functions ends after the last indented elif statement.

Python code:
def CharAttr():
    CharName1 = input("What is your first character's name?\n")
    CharStr1 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl1 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharName2 = input("What is your second character's name?\n")
    CharStr2 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr2 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl2 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl2 < 1:
        print("Invalid Input.")
        CharAttr()
All the variables that fall under CharAttr() are local to the function itself (only accessible within CharAttr()), not the entire program.

You have three options:
  1. Include the rest of your code under the CharAttr() function by indenting all of the lines
  2. Return the values from the CharAttr() function back to the __main__ part of the program (you could return dict with key/value pairs, a character class, a list, a tuple, whatever) and create new variables in the __main__ part of your program to assign these values to.
  3. Make these variables global (don't kill me thread) by instantiating them at the top of your program and then using the global keyword within your CharAttr() and __main__ functions.

so I included everything in one function and called it at the end of the file
Python code:
#Encounter Outcome Program
import random #imports the random feature, allows randomisation of given values

def CharAttr():
    CharName1 = input("What is your first character's name?\n")
    CharStr1 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl1 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl1 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl1 < 1:
        print("Invalid Input.")
        CharAttr()
    CharName2 = input("What is your second character's name?\n")
    CharStr2 = int(input("How powerful is your character, on a scale of 1-100?\n"))
    if CharStr2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharStr2 < 1:
        print("Invalid Input.")
        CharAttr()
    CharSkl2 = int(input("How skillful is your character, on a scale of 1-100?\n"))
    if CharSkl2 > 100:
        print("Invalid Input.")
        CharAttr()
    elif CharSkl2 < 1:
        print("Invalid Input.")
        CharAttr()

    StrengthMod = abs(CharStr1 - CharStr2)//5
    SkillMod = abs(CharSkl1 - CharSkl2)//5
    CharDice1 = random.randint(1, 6) #dice
    CharDice2 = random.randint(1, 6) #rolls

    if CharDice1 > CharDice2: #first character wins
            CharStr1 = CharStr1 + StrengthMod
            CharSkl1 = CharSkl1 + SkillMod
            CharStr2 = CharStr2 - StrengthMod
            CharSkl2 = CharSkl2 - SkillMod

    elif CharDice1 < CharDice2: #second character wins
            CharStr1 = CharStr1 - StrengthMod
            CharSkl1 = CharSkl1 - SkillMod
            CharStr2 = CharStr2 + StrengthMod
            CharSkl2 = CharSkl2 + SkillMod
    else:
        print("The Characters were too evenly matched, therefore no encounter occurred!")
        exit(0) #exits if draw occurs

    if CharSkl1 < 1:
        CharSkl1 = 0

    elif CharSkl2 < 1:
        CharSkl2 = 0

    if CharStr1 < 1:
        print(CharName1, "is now dead")

    elif CharStr2 < 1:
        print(CharName2, "is now dead")

    if CharStr1 and CharStr2 and CharSkl1 and CharSkl2 > 0:
        print(CharName1, "ended the fight with a Strength of", CharStr1, "and a Skill of", CharSkl1)
        print(CharName2, "ended the fight with a Strength of", CharStr2, "and a Skill of", CharSkl2)
        if CharStr1 and CharSkl1 > CharStr2 and CharSkl2:
            print(CharName1, "won!\n")
            print("The program has now finished")
            exit(0)
        elif CharStr2 and CharSkl2 > CharStr1 and CharSkl1:
            print(CharName2, "won!\n")
            print("The program has now finished")
            exit(0)
        else: 
            print("The program has now finished")
            exit(0)

CharAttr()
but now I get another traceback error when my program tries to validate a user's input.
instead of giving a numerical value for one of the character's attributes, I typed a word in to test the validation.

qntm
Jun 17, 2009

QuarkJets posted:

I like the look of 4 spaces, 2 spaces barely looks different from 1

Set your tab size to a single space, then use four tabs.

Lyon
Apr 17, 2003
Well don't do that! Your validation assumes that the end user is passing in a number and only checks to make sure it falls within a specific range. You're not doing any form of type validation.

Also... using option number one is probably the fastest way to get your program running but option number two was really the correct solution. You'll want to learn about returning values from your functions (and passing arguments into functions too).

SurgicalOntologist
Jun 17, 2004

lufty posted:

but now I get another traceback error when my program tries to validate a user's input.
instead of giving a numerical value for one of the character's attributes, I typed a word in to test the validation.

And what did you expect to happen? It seems reasonable to get an error here.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe
You want to get a number from the user and convert it into a Python integer using int(), but you want the program to be able to react if the user doesn't supply something that can be recognised as a number.

Try running this code and see if you can use something similar in your function.

code:
def square ():
    try:
        x = int(input("Enter a number.\n"))
        print("The square of your number is %d." % (x ** 2))
    except ValueError:
        print("That doesn't seem to be a number.")

square()

Literally Elvis
Oct 21, 2013

I'm new to python and building a web scraper using HTMLParser. I'm using this altered code sample almost exactly from the HTMLParser page:
code:
ndchars = ['[', ']', '"', ' ', ' \n ', 'Issue Date', 'Artist(s)', 'Reference']

class MyHTMLParser(HTMLParser):
    def handle_data(self, data):
        if data in ndchars:
            data = None
        else:
            print("Data found:", data)
However, the results I get are littered with newlines and spaces, which is what I tried to avoid by putting that stuff in ndchars. I get stuff like:

quote:

Date found! December 19
Data found:

Data found:

Data found:

Data found:

Date found! December 26
Data found:

Data found:

Data found:
I've tried saving the results as a string and using .rstrip() on them, to no avail. I'm certain this is super simple to fix, but I just can't manage to figure it out. Any ideas?

lufty
Jan 26, 2014

Hammerite posted:

You want to get a number from the user and convert it into a Python integer using int(), but you want the program to be able to react if the user doesn't supply something that can be recognised as a number.

Try running this code and see if you can use something similar in your function.

code:
def square ():
    try:
        x = int(input("Enter a number.\n"))
        print("The square of your number is %d." % (x ** 2))
    except ValueError:
        print("That doesn't seem to be a number.")

square()

"except" is invalid syntax apparently

supercrooky
Sep 12, 2006

Literally Elvis posted:

I'm new to python and building a web scraper using HTMLParser. I'm using this altered code sample almost exactly from the HTMLParser page:
code:
ndchars = ['[', ']', '"', ' ', ' \n ', 'Issue Date', 'Artist(s)', 'Reference']

class MyHTMLParser(HTMLParser):
    def handle_data(self, data):
        if data in ndchars:
            data = None
        else:
            print("Data found:", data)
However, the results I get are littered with newlines and spaces, which is what I tried to avoid by putting that stuff in ndchars. I get stuff like:

I've tried saving the results as a string and using .rstrip() on them, to no avail. I'm certain this is super simple to fix, but I just can't manage to figure it out. Any ideas?

You should post your complete code and data, that code doesn't produce that output by itself. But best guess is that "if data in ndchars" doesn't work how you think it does, and would let '\n', ' \n', '\n ', '\r\n' and some other stuff through.

KICK BAMA KICK
Mar 2, 2009

Lufty: One tiny thing, just cause I think I remember you doing it in an earlier post too. You really don't need to include an explanatory comment when you're importing something ubiquitous from the standard library with an unmistakable name like "random".

Literally Elvis
Oct 21, 2013

supercrooky posted:

You should post your complete code and data, that code doesn't produce that output by itself. But best guess is that "if data in ndchars" doesn't work how you think it does, and would let '\n', ' \n', '\n ', '\r\n' and some other stuff through.

Actually, just adding '\n' worked fine. I am a doofus. v:shobon:v

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

lufty posted:

"except" is invalid syntax apparently

Are you quite sure you didn't make any errors entering/copy-pasting the code from my post? There shouldn't be any issue with the "except" keyword. Try copy-pasting the code into a text file and running the file as a script.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.





:what: welp, at least there's a workaround, but am I doing something fantastically stupid here? I mean, even stupider than my normal level.

To be clear, you're seeing sorted fail to finish sorting when I hand it the output of Series.clip.

SurgicalOntologist
Jun 17, 2004

Isn't there a sorted method of Series? If so it's probably more reliable. In any case you should report this on the pandas github.

QuarkJets
Sep 8, 2008

lufty posted:

but now I get another traceback error when my program tries to validate a user's input.
instead of giving a numerical value for one of the character's attributes, I typed a word in to test the validation.



Basically you did this:

code:
int('number')
Python doesn't know how to turn your word into an integer, so it raised an error

And 'except' is definitely valid syntax. Can you provide the code block that you're testing and the error? The example that Hammerite provided is almost identical to the example that the Python docs use to introduce exception handling: https://docs.python.org/2/tutorial/errors.html#handling-exceptions

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

QuarkJets posted:

Basically you did this:

code:
int('number')
Python doesn't know how to turn your word into an integer, so it raised an error

And 'except' is definitely valid syntax. Can you provide the code block that you're testing and the error? The example that Hammerite provided is almost identical to the example that the Python docs use to introduce exception handling: https://docs.python.org/2/tutorial/errors.html#handling-exceptions

He could have got that error message if he didn't type both closing brackets on the previous line.

the
Jul 18, 2004

by Cowcaster
I'm programming a self-avoiding random walk. My question is: How would I get it so I could watch it walk in real-time? All I can do right now is just look at the completed Pylab plot after it's done.

more like dICK
Feb 15, 2010

This is inevitable.
turtle is perfect for simple line drawings.

the
Jul 18, 2004

by Cowcaster

more like dICK posted:

turtle is perfect for simple line drawings.

Interesting. I basically want to real-time plot about 10000 x,y coords.

SurgicalOntologist
Jun 17, 2004

Well you could make a loop with time.sleep in-between every plot of a new point. Matplotlib can do animation more directly but that's a simple option you could try.

Adbot
ADBOT LOVES YOU

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



SurgicalOntologist posted:

Isn't there a sorted method of Series? If so it's probably more reliable. In any case you should report this on the pandas github.

The only one I can find is for an Index, but I only started using Pandas on Tuesday, so my knowledge and understanding of its capabilities is very much lacking :)

  • Locked thread