|
hooah posted:Any idea why, after debugging once, PyCharm wants to always debug, even though I'm hitting the "run" hotkey? Check which hotkey you're using, there's one for run and one for "do whichever thing I did last again".
|
# ? Mar 17, 2015 01:02 |
|
|
# ? May 24, 2024 20:03 |
|
Did this get good in the past year? In the past this thread has always been quite negative on diveintopython. The two recommendations of this thread have always been Learn Python the Hard Way and Think Python. Of course, those are aimed at a beginner. If someone is familiar with programming, I'm not sure what the best resource would be...
|
# ? Mar 17, 2015 01:07 |
|
Thermopyle posted:Did this get good in the past year? In the past this thread has always been quite negative on diveintopython. Yeah I kind of recall someone I respected disparaging "the Hard Way" on here. I share your thoughts at the end though, I was thinking at the very least a person familiar with perl could skim the sections on data structures and functions to get started, then pick up the other pieces as they use them.
|
# ? Mar 17, 2015 01:55 |
salisbury shake posted:You're calling logging.info and not info on the instance of your logger. The name of the logger needs to be in the scope of the function that needs to use it. There are different ways to go about this. I used a module level logger that I imported in different components in my last project. You can name it at the top of your file, make it an class attribute, etc. Ok I fixed that but it seems like the location of the "from myproj.utils import execute" is still important because when I have it at the top of the file (before it hits my setup_logging method) then myproj.utils doesn't seem to get the modified logging config.
|
|
# ? Mar 17, 2015 02:05 |
|
EAT THE EGGS RICOLA posted:Check which hotkey you're using, there's one for run and one for "do whichever thing I did last again". Yup, that was it. Apparently whoever made the Visual Studio-like keybindings bound ctrl+f5 to two different commands. Good job, folks.
|
# ? Mar 17, 2015 02:26 |
|
EAT THE EGGS RICOLA posted:Check which hotkey you're using, there's one for run and one for "do whichever thing I did last again". Hey that's pretty handy! For those of you wondering, you can get to that menu from "Help->Find Action..." or Ctrl+Shift+A (depending on your shortcuts).
|
# ? Mar 17, 2015 04:48 |
|
Thermopyle posted:Did this get good in the past year? In the past this thread has always been quite negative on diveintopython. I remember some people having negative opinions of Dive Into Python as well, but I couldn't find anything well I was work. My problem with Learn Python the Hard Way is that it is specific to Python 2, and I think it is about time that Python3 be the standard. In the end, I recommended the tutorial from the official documentation.
|
# ? Mar 17, 2015 04:52 |
|
accipter posted:Hey that's pretty handy! For those of you wondering, you can get to that menu from "Help->Find Action..." or Ctrl+Shift+A (depending on your shortcuts). Oh, yeah, this feature owns. You can look up any action with ctrl-shift-A followed by typing in any command.
|
# ? Mar 17, 2015 12:50 |
|
What is a simple way to parse information out of an HTML document? My work has an application that renders forms using HTML but it's not a website. I want to run through a file and any input element it sees, it should record the type, name and value. I'm assuming I don't want to use regex to parse html...
|
# ? Mar 18, 2015 02:37 |
|
Hughmoris posted:What is a simple way to parse information out of an HTML document? My work has an application that renders forms using HTML but it's not a website. I want to run through a file and any input element it sees, it should record the type, name and value. I'm assuming I don't want to use regex to parse html... There are libraries like BeautifulSoup that will help parse HTML for you. I've used BeautifulSoup in the past and it was straightforward to pickup.
|
# ? Mar 18, 2015 02:42 |
|
Hughmoris posted:What is a simple way to parse information out of an HTML document? My work has an application that renders forms using HTML but it's not a website. I want to run through a file and any input element it sees, it should record the type, name and value. I'm assuming I don't want to use regex to parse html... BeautifulSoup is nice.
|
# ? Mar 18, 2015 02:42 |
Hughmoris posted:What is a simple way to parse information out of an HTML document? My work has an application that renders forms using HTML but it's not a website. I want to run through a file and any input element it sees, it should record the type, name and value. I'm assuming I don't want to use regex to parse html... This should be a piece of cake with bs4: http://www.crummy.com/software/BeautifulSoup/bs4/doc/ edit: drat you guys are fast
|
|
# ? Mar 18, 2015 02:43 |
|
Wow, thanks. Looks like BeautifulSoup is what I'll try. I looked at it months ago and was a little overwhelmed but I've learned a little HTML since then so hopefully this time I'll make some progress.
|
# ? Mar 18, 2015 02:45 |
|
Hughmoris posted:What is a simple way to parse information out of an HTML document? My work has an application that renders forms using HTML but it's not a website. I want to run through a file and any input element it sees, it should record the type, name and value. I'm assuming I don't want to use regex to parse html... You might also want to consider lxml.html.
|
# ? Mar 18, 2015 04:18 |
|
Maybe I should wait a bit to learn how to do python like this, but I'm trying to do things in as little code as possible. an example is from way back in the thread, trying to do something similar to this. Dominoes posted:Putting it all together: Still doing the code academy stuff and it's on the "practice by yourself" and I'm doing a really incredibly simple "add the numbers of an integer" type function. The "answer" they are looking for is something like this: code:
|
# ? Mar 19, 2015 14:52 |
|
Just found an old game I wrote in about 2006-2007 and it has super calls like this:code:
Any idea why its not done that way anymore? It strikes me as a less boilercode-ish way of calling super.
|
# ? Mar 19, 2015 14:53 |
|
Gothmog1065 posted:Maybe I should wait a bit to learn how to do python like this, but I'm trying to do things in as little code as possible. an example is from way back in the thread, trying to do something similar to this. The first example is okay because it's pretty clear, but you shouldn't be trying to write clever code, you should be trying to write code that is as clear as possible for someone else (including you in the future) to read. Following pep8 helps a lot with this.
|
# ? Mar 19, 2015 15:02 |
|
EAT THE EGGS RICOLA posted:The first example is okay because it's pretty clear, but you shouldn't be trying to write clever code, you should be trying to write code that is as clear as possible for someone else (including you in the future) to read. Following pep8 helps a lot with this. Alright. That's kind of what I was looking for in an answer, I'll move on!
|
# ? Mar 19, 2015 15:08 |
|
Gothmog1065 posted:Still doing the code academy stuff and it's on the "practice by yourself" and I'm doing a really incredibly simple "add the numbers of an integer" type function. The "answer" they are looking for is something like this: First, identify that that code pattern is a sum. Python code:
Python code:
Python code:
|
# ? Mar 19, 2015 15:15 |
|
Gothmog1065 posted:Alright. That's kind of what I was looking for in an answer, I'll move on! While generally what EGGS wrote is true, you shouldn't think that using sum and a list comprehension together to write something in one line as being too clever. As long as you're familiar with those constructs, then the code is entirely and clearly legible. Even if you're not, the syntax is so clear that you should be able to figure out what's going on. If you're ever writing code you think may be hard to read, then you should try to make it easier to read. Usually by naming methods and variables appropriately, and adding a comment or two explaining what's going on. Don't stop yourself from using clearly defined and understood language constructs just to avoid being 'clever'.
|
# ? Mar 19, 2015 15:20 |
|
cliffy posted:While generally what EGGS wrote is true, you shouldn't think that using sum and a list comprehension together to write something in one line as being too clever. As long as you're familiar with those constructs, then the code is entirely and clearly legible. Even if you're not, the syntax is so clear that you should be able to figure out what's going on. Yeah, the two examples you mentioned are totally fine in terms of clarity when they use list comprehensions, but it's best to keep readability in mind before you start doing that with significantly more complicated code.
|
# ? Mar 19, 2015 15:31 |
|
SurgicalOntologist posted:
Goddammit, I had the int() in the wrong place. Thanks guys, I kind of get excited and try to learn things ahead, which sometimes is a good thing, and sometimes bad.
|
# ? Mar 19, 2015 16:23 |
|
Surgical Ont answered your question, but since it's academic, two more things to think about : This accomplishes the same thing and is about as efficient, but is frowned upon (including by Guido) for being more difficult to read: Python code:
Dominoes fucked around with this message at 22:39 on Mar 19, 2015 |
# ? Mar 19, 2015 18:01 |
|
Just as an aside, learning how to effectively use the built-in functions map, reduce, and filter will make your code look and feel a lot simpler and cleaner.
|
# ? Mar 19, 2015 19:07 |
|
cliffy posted:Just as an aside, learning how to effectively use the built-in functions map, reduce, and filter will make your code look and feel a lot simpler and cleaner. This is true, with the stress heavily on effectively. The majority of the time that I see those used they're just code golf. I mean, I don't know if that's true over all Python code, or if it's just true over the Python code I happen to read, but they're easy to abuse.
|
# ? Mar 19, 2015 19:21 |
|
Or you could go full functional style.Python code:
|
# ? Mar 19, 2015 20:46 |
|
What's wrong with using a functional style? I don't know that much about it but from hacking around with SICP/Scheme it seems pretty intuitive(moreso than a procedural style, honestly), and it looks like the tools are there to do it in Python.
|
# ? Mar 19, 2015 20:59 |
|
Fergus Mac Roich posted:What's wrong with using a functional style? Nothing.
|
# ? Mar 19, 2015 21:01 |
|
What would the original, list-comprehension one be called? What ”style" is that? (My Python is like 75% list comprehensions these days.)
|
# ? Mar 19, 2015 21:10 |
|
The only thing "wrong" with a functional style is it's not mainstream Python, so your typical Python programmer is not likely to have encountered it and will be confused. Cingulate, I don't know about identifying a style (it's not really clear cut, even my version isn't functional in the more academic sense), but it's worth pointing out that there's no list comprehension, but a generator expression. You shouldn't have 75% list comprehensions, but a lot of generator expressions/comprehensions of all kinds is usually considered the best way to write Python code.
|
# ? Mar 19, 2015 21:14 |
|
SurgicalOntologist posted:Or you could go full functional style. Alternatively - Python code:
Python code:
Dominoes fucked around with this message at 22:34 on Mar 19, 2015 |
# ? Mar 19, 2015 22:25 |
|
I tend to use map, reduce and filter quite a bit, but honestly it has a tendency to make the code harder to explain other than "this is the effect, but how it works might take some time". Be careful with it, good python is about being able to just glance at the code and see how it works. That is not always the case with some of the functional primitives in python.
|
# ? Mar 20, 2015 02:42 |
|
I haven't used map or filter in years. List comprehensions and generator expressions
BigRedDot fucked around with this message at 03:18 on Mar 20, 2015 |
# ? Mar 20, 2015 03:15 |
|
Beating my head against a wall here (as usual). In IDLE, when I do this: code:
code:
I can't for the life of my figure out why res[1][0] and res[2][0] are getting changed as well. Working on a matrix translation problem, and eventually I will add the code code:
|
# ? Mar 20, 2015 07:33 |
|
You aren't copying the list.
|
# ? Mar 20, 2015 08:20 |
|
KaneTW posted:You aren't copying the list. I'm afraid I don't understand. Could you provide a little more detail?
|
# ? Mar 20, 2015 08:23 |
|
Your matrix consists of three times the "new_row" object. If you change the first element of "new_row" to a "!", of course it will show up in all three rows. res.append(list(new_row)) should work better since you are creating a new copy of the list each time instead of adding the same object.
|
# ? Mar 20, 2015 08:32 |
|
Lists in Python aren't copied by default, socode:
Consider using an existing matrix library.
|
# ? Mar 20, 2015 08:32 |
|
You should use numpy if you're going to work with matrices.
|
# ? Mar 20, 2015 09:16 |
|
|
# ? May 24, 2024 20:03 |
|
Ahh thank you! I feel silly now. I'm just doing some practice problems on CheckIO but thanks for the suggestions about working further with matrices.
|
# ? Mar 20, 2015 12:45 |