|
I highly recommend using the free version of pycharm. It will edit your code and make it pep8 compliant.
|
# ? Jul 3, 2014 23:35 |
|
|
# ? May 9, 2024 11:32 |
|
EAT THE EGGS RICOLA posted:Use actual words, don't put compound statements on one line, get rid of most of the comments (your code should self-document for something this simple), put the declarations on separate lines, and join your string like this: so i tried to change what you meant. I'm just not sure on the code you added since i've never used it, i'm not sure exactly how to implement it. but from what i read it seems you append the new letter to the list per loop and once ending the loop you .join the list turning into a string before print i'm guessing. Well my modified code came out as such: code:
|
# ? Jul 3, 2014 23:36 |
|
HardDisk posted:Don't use tabs. Use spaces, preferably 4. Set your tab size to a single space, then indent using four tabs.
|
# ? Jul 3, 2014 23:46 |
|
Yes, the code I posted is to build a list with your final string as elements, then to just join that list once instead of building a new string every time you add a character. Ignoring anything else, this is what you get when you inspect this code with pycharm: code:
|
# ? Jul 3, 2014 23:59 |
|
okay so final edit for learning purposes this is what i ended up with.code:
|
# ? Jul 4, 2014 01:43 |
|
You also need some blank lines for readability. I can't think of the studies right now to quote, but something like this:Python code:
|
# ? Jul 4, 2014 02:03 |
|
theguyoncouch posted:okay so final edit for learning purposes this is what i ended up with. see comments in code
|
# ? Jul 4, 2014 02:11 |
|
good jovi posted:see comments in code you're completely correct i never modify char so that should totally work. and yeah i didn't notice. at first i was trying to compress my code into as little lines as possible but i guess that just leaves a mess unless you know what you're looking at.
|
# ? Jul 4, 2014 02:17 |
|
theguyoncouch posted:you're completely correct i never modify char so that should totally work. and yeah i didn't notice. at first i was trying to compress my code into as little lines as possible but i guess that just leaves a mess unless you know what you're looking at. Because python is so whitespace dependent, avoiding putting compound statements on one line is really important because it improves readability by a huge amount.
|
# ? Jul 4, 2014 02:31 |
|
I suppose it's easy to hear people brag about how they did x thing in y lines of code. But from what you guys have said, line count is really only a consideration when it's way larger than you think it should be (indicating the need for optimization)?
|
# ? Jul 4, 2014 02:51 |
|
Low line count doesn't matter at all in professional programming. All that matters is how easy something is to read and modify/extend/maintain. You read a lot about people proud that they deleted a hundred lines of code and replaced them with 20 lines, but that's usually because the initial code was repetitive and inefficient, not because 20 lines is inherently better than 100.
|
# ? Jul 4, 2014 02:58 |
|
Thermopyle posted:You also need some blank lines for readability. I can't think of the studies right now to quote, but something like this: qntm posted:Set your tab size to a single space, then indent using four tabs. The best option, IMO, is to set tabs to convert to four spaces.
|
# ? Jul 4, 2014 03:18 |
|
The best best option is not to argue about tabs vs spaces. Pep8 recommends 4 spaces and most python programmers try to follow pep8. Please let that be the end of it.
|
# ? Jul 4, 2014 04:29 |
|
What's the preferred way to install Py3.4 on OS X these days? Brew installs 3.3 by default. I'm trying to get my virtualenvs as easy as it is on my Ubuntu boxes. Should I just install the official binaries and symlink /usr/bin/local then pyvenv my way to enlightenment?
|
# ? Jul 4, 2014 04:30 |
|
good jovi posted:The best best option is not to argue about tabs vs spaces. Pep8 recommends 4 spaces and most python programmers try to follow pep8. Please let that be the end of it. It doesn't matter but if you're a beginner not too used to forced indentation, using only spaces is a lot less confusing. From me it's a strong recommendation, people complain a lot about this aspect of python BECAUSE they mix tabs and spaces. With that said theguyonthecouch seemed to be doing well at consistently using only tabs. Hed posted:What's the preferred way to install Py3.4 on OS X these days? Brew installs 3.3 by default. I'm trying to get my virtualenvs as easy as it is on my Ubuntu boxes. I like Anaconda. It sets up stuff like numpy and scipy in the least painful way.
|
# ? Jul 4, 2014 04:43 |
|
Hed posted:What's the preferred way to install Py3.4 on OS X these days? Brew installs 3.3 by default. I'm trying to get my virtualenvs as easy as it is on my Ubuntu boxes. I've always been happy with the official binary installers. I believe they put symlinks in /usr/bin/local themselves, but I just keep my PATH updated to make it explicit.
|
# ? Jul 4, 2014 04:43 |
|
good jovi posted:The best best option is not to argue about tabs vs spaces. Pep8 recommends 4 spaces and most python programmers try to follow pep8. Please let that be the end of it. You should basically just do this unless you're working with some legacy code that uses tabs or weird spacing, I think.
|
# ? Jul 4, 2014 04:46 |
|
Superior indenting is to use tabs that expand to 3 spaces
|
# ? Jul 4, 2014 05:44 |
|
Hed posted:What's the preferred way to install Py3.4 on OS X these days? Brew installs 3.3 by default. I'm trying to get my virtualenvs as easy as it is on my Ubuntu boxes. Python 3.4 (or 3.3 or 2.7 or 2.6 or all of the above) environments are super easy to create with conda (the package manager for Anaconda).
|
# ? Jul 4, 2014 06:56 |
|
theguyoncouch posted:okay so final edit for learning purposes this is what i ended up with. You don't need to do this. You can just do: code:
|
# ? Jul 4, 2014 15:53 |
|
BeefofAges posted:You don't need to do this. You can just do: I almost always just do "if condition:", but it can be okay to do "if condition is True:" if it improves readability (which it doesn't in this case).
|
# ? Jul 4, 2014 16:24 |
|
I am in the learning stages if Python. Has anyone with any experience done the code academy python course? It seem solid but I don't want to complete it if it's teaching bad habits to generally not up to scratch. I like the instant compiler aspect and the saving function of the site so I can do an hour here or there. I ultimately want to move this knowledge over to swift but that's a long way off as I am struggling enough as it is.
|
# ? Jul 4, 2014 16:44 |
|
thegasman2000 posted:I am in the learning stages if Python. Has anyone with any experience done the code academy python course? It seem solid but I don't want to complete it if it's teaching bad habits to generally not up to scratch. I like the instant compiler aspect and the saving function of the site so I can do an hour here or there. Think of learning to program as an iterative process. There's a lot to learn and it might be better to quickly pick up concepts and then refine them later with all the correct patterns. As you work on more projects, you'll pick up tips and tricks from colleagues around you. The o'reilly book on advanced Python is quite good after you've played with Python for a couple months.
|
# ? Jul 4, 2014 16:47 |
|
EAT THE EGGS RICOLA posted:I almost always just do "if condition:", but it can be okay to do "if condition is True:" if it improves readability (which it doesn't in this case). Those are semantically different things
|
# ? Jul 4, 2014 16:54 |
|
'is' in python is not really the same is '==', correct?
|
# ? Jul 4, 2014 16:57 |
|
thegasman2000 posted:I am in the learning stages if Python. Has anyone with any experience done the code academy python course? It seem solid but I don't want to complete it if it's teaching bad habits to generally not up to scratch. I like the instant compiler aspect and the saving function of the site so I can do an hour here or there.
|
# ? Jul 4, 2014 17:00 |
|
Cultural Imperial posted:'is' in python is not really the same is '==', correct? It's not.
|
# ? Jul 4, 2014 17:23 |
|
You're of course right, that's what I get for posting while tired/busy.
|
# ? Jul 4, 2014 17:24 |
|
Cultural Imperial posted:'is' in python is not really the same is '==', correct? I think that if x is y, then x == y, and if id(x)==id(y) then x is y. There is a unique True, a unique False, and a unique None, so either comparison works, e.g. x==None and x is None should do the same thing. Also, this probably only the case with built-in objects. If you've made your own class, then the behaviour of == depends on the __eq__ method.
|
# ? Jul 4, 2014 20:15 |
|
It should really be a syntax error to have a file that mixes tabs and spaces for indentation.
|
# ? Jul 5, 2014 00:02 |
|
Hammerite posted:It should really be a syntax error to have a file that mixes tabs and spaces for indentation. It is. EDIT: It's specifically a TabError, which is a subclass of SyntaxError. Lysidas fucked around with this message at 00:09 on Jul 5, 2014 |
# ? Jul 5, 2014 00:06 |
|
Lysidas posted:It is. No it isn't. This file runs without any errors: code:
|
# ? Jul 5, 2014 00:10 |
|
Hammerite posted:No it isn't. This file runs without any errors: Ah, forgot about that. A TabError is only raised on execution or import when they're on adjacent lines. Resetting the indent stack to 0 prevents the exception. Good point.
|
# ? Jul 5, 2014 00:15 |
|
Lysidas posted:Ah, forgot about that. A TabError is only raised on execution or import when they're on adjacent lines. Resetting the indent stack to 0 prevents the exception. Good point. Well, this also works: code:
|
# ? Jul 5, 2014 00:22 |
|
Run python with the -tt argument to get errors for mixed tabs/spaces. https://docs.python.org/2/using/cmdline.html#cmdoption-t Hmm, did they get rid of this in 3.x? BeefofAges fucked around with this message at 10:09 on Jul 5, 2014 |
# ? Jul 5, 2014 10:06 |
|
theguyoncouch posted:okay so final edit for learning purposes this is what i ended up with. instead of readability, let's look at structure - You have a bunch of magic numbers in your code - You have a flag "uppercase_check", which is really more "is_uppercase". It might be easier to duplicate code a little than to have a flag variable. - You should really pass in shift as a variable too. I tend to go with things like "n" when it's just a number Anyway, you could try and decompose it into smaller chunks, splitting things like the rotation operation from the handling for upper and lower case letters. code:
|
# ? Jul 5, 2014 11:10 |
|
BeefofAges posted:Run python with the -tt argument to get errors for mixed tabs/spaces. I found it surprisingly difficult to find information on this, but according to this mailing list page https://mail.python.org/pipermail/python-3000/2008-June/013990.html the option was removed because it's now the default behaviour. Anyway, it isn't strict enough, as I say. I was running the code samples in my previous posts in Python 3.
|
# ? Jul 5, 2014 12:57 |
|
Cultural Imperial posted:'is' in python is not really the same is '==', correct? x == y if x and y have the same value, as determined by comparison magic (which includes looking for __eq__/__cmp__ methods and so on). x is y if x and y are the same object (i.e. id(x) == id(y)). Integers between -5 and 256 and short strings are cached, which is what tends to confuse people. if butt == None is unsafe, because butt might be a naughty object whose __eq__ method returns True when compared with None.
|
# ? Jul 6, 2014 11:33 |
|
When it comes to testing None, True, and False, always use "is" when comparing to None and just use the actual boolean value of your object instead of comparing to True or False
|
# ? Jul 6, 2014 21:44 |
|
|
# ? May 9, 2024 11:32 |
|
I'm new to Python and programming in general. I just finished my first program - a game created with Python 2.7, Pyglet, and Cocos2D. I'm having two major problems. 1. Since I'm new to programming, I never considered the game running its update functions at different rates on different computers. One of my classes contains the main game's sprites. The update function for this class applies gravity when the sprite is jumping. On my computer, this was applied 60 times per second. I tested on another computer though, and it seems to be applied at a much faster rate, which results in the sprite barely jumping off the ground. 2. I want to convert this game to an exe file so others can play it. I did this using PyInstaller, and got the exe file to run successfully on my own computer. I ran into trouble on another computer, though. The game runs but there's a weird graphical glitch - there's one sprite that is displayed as a white block.
|
# ? Jul 7, 2014 15:26 |