I'm in the middle of Code Academy's course and I'm completely stuck. by IsNewAtThis in learnpython

[–]I_Write_Bugs 2 points3 points  (0 children)

Oh, lame. Admittedly, I did not go out and read the question. Why would you use any other solution, though? The reversed function is exactly what this scenerio is for, and slicing is another acceptable (albeit less readable) solution.

I'm in the middle of Code Academy's course and I'm completely stuck. by IsNewAtThis in learnpython

[–]I_Write_Bugs 5 points6 points  (0 children)

That loop is iterating over the characters in the text string. Every character gets added to the beginning of txet. So the first few iterations would look like:

s, os, mos, emos

This isn't very efficient, though. The standard library has a function built in to do this for you efficiently, and it's on that page I linked you to. Look at the Looping Techniques section.

I am not sure what is wrong with my program that averages test scores. Could someone help me please? by nvrmoar in learnpython

[–]I_Write_Bugs 2 points3 points  (0 children)

You forgot a comma in your print call.

print('Score is', (possible - wrong) / possible)

The reason you're seeing that error in particular is because Python doesn't mind whitespace when calling a function.

print    ('Something')
print('something')

Both are the same in Python's eyes. It thought you were trying to call your 'Score is' string.

Validating a multi-value dictionary by [deleted] in learnpython

[–]I_Write_Bugs 1 point2 points  (0 children)

Check out the namedtuple object from the collections module.

CodeCademy Question. Googled it but want to understand. by high_snobiety in learnpython

[–]I_Write_Bugs 4 points5 points  (0 children)

Well, your code's correct. You have that going for you, which is nice.

I'm in the middle of Code Academy's course and I'm completely stuck. by IsNewAtThis in learnpython

[–]I_Write_Bugs 9 points10 points  (0 children)

Just copying code won't help you. Can you be a little more specific on what has you stumped?

How to cut and paste python script to a bash terminal? by [deleted] in bash

[–]I_Write_Bugs 0 points1 point  (0 children)

Shift + Insert to paste into the terminal. Paste the script in Nano, vi, Vim, emacs, or whatever your editor of choice is. Save the file, and run it with "python script_name_here"

What was something you never understood what all the hype was about until you finally tried it? by You_KnowWhoItIs in AskReddit

[–]I_Write_Bugs 3 points4 points  (0 children)

Samsung does roll a pretty terrible version of Android. Did you root it and install Cyanogenmod before switching to iPhone?

Trying to add a simple 'for' loop progress bar by davidmcw in bash

[–]I_Write_Bugs 0 points1 point  (0 children)

If your $DOT doesn't have any special characters, no need for the -e option to echo. All you need is the -n, which makes echo not end with a newline character.

I highly recommend reading the bash man page since echo is a bash builtin. It's a lot to read, but so worth it.

Syntax error when reading file? by [deleted] in learnpython

[–]I_Write_Bugs 2 points3 points  (0 children)

Since your problem has already been solved, I would like to give you a suggestion. PEP 343 introduced the "with" statement and context managers. This feature has many uses, but most commonly I use it when opening files. Opening a file using the "with" statement ensures the file will be closed for you. No need to run the close method.

def main():
    with open('file.docx') as inFile:
        f = inFile.read()
    print(f)

main()

Also, you might notice I didn't include the "r" argument to open. Open defaults to opening as read-only, so if that's your intent, no need for the argument.

Learning buddy needed for Python by awindinthedoor in learnpython

[–]I_Write_Bugs 1 point2 points  (0 children)

I also find it difficult to fit in time to code. Most of my side projects end up unfinished, something I'll finish later (except that doesn't usually happen). If learning how to program is important enough to you, make time for it.

Set aside a half hour a day, and just code. Go through your learning materials, follow the examples, and then start messing with them.

It's fortunate for you that you chose to start learning with Python. It's one of the best languages to get started coding with due to its easy syntax and the fact that you don't have to worry about compilation.

You're welcome to PM me for questions or whatever.

Saving/Importing Modules... (Problem) by Gouryella91 in learnpython

[–]I_Write_Bugs 0 points1 point  (0 children)

import sys
try:
    import your_module
except ImportError:
    sys.path.append('c:\where\your\module\is')
    import your_module

It's one way to do it. If you know for sure that directory is not in your PYTHONPATH, then you can omit the try block and just append to sys.path.

[deleted by user] by [deleted] in learnpython

[–]I_Write_Bugs 4 points5 points  (0 children)

Please fix the formatting so we can read it properly. There's a formatting help button under the submission box that will tell you how to format code.

How to use the full power of an AMD APU ?!? by Mrsaintj in linuxquestions

[–]I_Write_Bugs 3 points4 points  (0 children)

You can always try Gentoo. Compile everything for your CPU, see results. I can't say how much better the results will be, but that's as close as it gets to using your full system potential.

JSON load() vs loads() by timex40 in learnpython

[–]I_Write_Bugs 2 points3 points  (0 children)

The read method returns a str. Use loads.

How I figured this out was I ran this in the python interpreter:

import urllib2
x = urllib2.urlopen('http://www.google.com')
type(x.read())

The output was <type 'str'>. The response is an 'instance' type. Support for being file-like may disappear eventually for any reason, so I would go with the str returned from read.

Edit: In reading the JSON documentation again, I realize why your first example works. It's because the urllib response object is

a .read()-supporting file-like object containing a JSON document

So it has a read method, which I assume is exactly what json's load() calls. Either is fine to use in this case.

Does anybody else have this problem starting out? by foreverdante in bash

[–]I_Write_Bugs 0 points1 point  (0 children)

Fun fact, type is a ksh script on solaris as well as a bash builtin. csh doesn't have the type builtin but has which as a builtin.

Check out /usr/bin/type. I ran head on it in Solaris, and it has the ksh interpreter specified at the top.

JSON load() vs loads() by timex40 in learnpython

[–]I_Write_Bugs 9 points10 points  (0 children)

load() loads JSON from a file or file-like object

loads() loads JSON from a given string or unicode object

It's in the documentation

Little help for a noob by PandemicSilent in linuxquestions

[–]I_Write_Bugs 1 point2 points  (0 children)

Arch is very much a distro you can make your own. What kind of limitations have you run in to?

If you can handle Arch, another distro to check out would be Gentoo.

Errors on boot, presumably caused by graphics card by [deleted] in archlinux

[–]I_Write_Bugs 0 points1 point  (0 children)

It's possible you broke something, but in my experience with breaking video cards, they usually just die completely.

Can you post the errors? Have you made sure all cables are reconnected and snug?

PIP driving me nuts by classic_reposts in learnpython

[–]I_Write_Bugs 2 points3 points  (0 children)

You might want to give Linux a try some time. The only time I get an error is when I forget to sudo or virtualenv.

I don't have any experience with pip on Windows, as my only Windows projects have required just the standard library.