|
Python 3.5 is out go get some! I haven't hosed with async io but I'm looking forward too the new unpacking generalizations
|
# ? Sep 13, 2015 19:22 |
|
|
# ? May 9, 2024 04:45 |
|
Hed posted:Python 3.5 is out go get some! code:
|
# ? Sep 13, 2015 23:10 |
|
PEP-484 makes tooling (like PyCharm) much better and is now in 3.5 I've been using it on Python 3.4 with PyCharm for a year or so and it's only gotten better. Quick summary: 484 adds type information to function signatures. Python code:
You can of course, use your own types: Python code:
Python code:
|
# ? Sep 13, 2015 23:53 |
|
I'm glad that made it into the official library; it's nice for documenting complex function arguments like heterogeneous collections.
|
# ? Sep 14, 2015 00:06 |
|
Is there (gonna be) a from __future__ import type_annotations thing? Also why do people continue to use python 2
|
# ? Sep 14, 2015 00:13 |
|
How do I get 3.5.0 in anaconda. I mean I see it there, taunting me, when I do a 'conda search python', but 3.4.3 is the "latest" version when I do a 'conda update python'. I've just started using anaconda, and I'm still fumbling around in it.
|
# ? Sep 14, 2015 00:14 |
|
flosofl posted:How do I get 3.5.0 in anaconda?
|
# ? Sep 14, 2015 00:16 |
|
Dominoes posted:Wait. Fair enough. I just wish it wouldn't list it as a result in the conda search like it could actually be installed.
|
# ? Sep 14, 2015 00:26 |
|
Thermopyle posted:PEP-484 makes tooling (like PyCharm) much better and is now in 3.5 I've been using it on Python 3.4 with PyCharm for a year or so and it's only gotten better. I really hope that at some point the interpreter will have a mode to enforce the type signatures if present, like a -t flag or something to that effect. Cingulate posted:Is there (gonna be) a from __future__ import type_annotations thing? Also why do people continue to use python 2 For Python 2? It's not getting anything new at this point and adding annotations to 2 would require a lot of work, the type signature stuff builds on the generic annotations that 3 introduced. As for why 2.x is still used... though most OpenStack stuff has to pass gates at both 2.7 and 3.4 now so it may be usable with 3.x by Mitaka, Twisted seems to be coming along (and a lot of what it does is subsumed into 3.5 anyway with all the async/await functionality), and Mercurial will probably eventually be clubbed into submission by the core Python developers.
|
# ? Sep 14, 2015 02:29 |
|
2.X is still used because it's not compatible with 3.X, and there are a bunch of systems with 2.X dependencies. That's the reason.
|
# ? Sep 14, 2015 02:40 |
|
Wasn't so much a question as a complaint. I'm contributing to a project that's required to run on both 2 and 3 and it makes my life ever so slightly worse.
|
# ? Sep 14, 2015 05:15 |
|
chutwig posted:I really hope that at some point the interpreter will have a mode to enforce the type signatures if present, like a -t flag or something to that effect. You can use MyPy to check types for you.
|
# ? Sep 14, 2015 14:11 |
|
Hed posted:Python 3.5 is out go get some! I still havent evolved from 2.7 yet. I probably should update my thinking. async seems to be the selling point to my line of thinking. As to why? Lotta legacy, and I've been hacking on python since the late 90s and old dogs/new tricks/etc
|
# ? Sep 14, 2015 17:34 |
|
OK so if anyone has time for a stupid question, I can't wrap my head for how something like this works. I was doing this exercise on for loops and definitions and I can't for the life of me figure out the importance of this exercise. Doesn't having mylist =[numbers] negate the whole function? If you remove it won't this run until infinity? I'm so over functions.code:
|
# ? Sep 14, 2015 18:37 |
|
Veskit posted:OK so if anyone has time for a stupid question, I can't wrap my head for how something like this works. I was doing this exercise on for loops and definitions and I can't for the life of me figure out the importance of this exercise. Doesn't having mylist =[numbers] negate the whole function? If you remove it won't this run until infinity? I'm so over functions. Why don't you try that and see?
|
# ? Sep 14, 2015 18:41 |
|
I'm not really sure what you are not understanding. Can you explain a bit more in depth? One thing in the meantime that you can do to hopefully make thing a bit clearer for yourself, is to add a few prints inside the for loop, for example, to print out the l and sum variables.
|
# ? Sep 14, 2015 18:43 |
|
Not sure if this helps your confusion as I can't even tell what your misconception is. But I thought I'd answer your questions literally at least.Veskit posted:Doesn't having mylist =[numbers] negate the whole function? No. All that line does is make a new list and assign it the name "mylist". The only way to "negate" the function would be to have a line like Python code:
Veskit posted:If you remove it won't this run until infinity? I'm so over functions. Try it! If you remove the line mylist = [1,2,3,4,5], you will get an error on the next line, "The name 'mylist' is not defined". The mylist line is making a list; the next line is passing it to your function. There's nothing unusual or tricky in those last two lines. Completely normal thing to do after you make a function: create a sample input, pass it to the function, and print the result.
|
# ? Sep 14, 2015 18:45 |
|
Veskit posted:OK so if anyone has time for a stupid question, I can't wrap my head for how something like this works. I was doing this exercise on for loops and definitions and I can't for the life of me figure out the importance of this exercise. Doesn't having mylist =[numbers] negate the whole function? If you remove it won't this run until infinity? I'm so over functions. I don't know what it means to negate a function. You can answer your questions about what happens if you remove the line mylist = [1,2,3,4,5] by removing the line and seeing what happens: NameError: name 'mylist' is not defined It would help us help you if you could more precisely describe what it means for mylist = [numbers] to negate the function, and also, why you expect the program to run until infinity if you removed that line. This reflects some operational misunderstanding of how Python works, but I can't unravel it.
|
# ? Sep 14, 2015 18:47 |
|
Sorry, if I just write code:
For reference I was trying to find more info on functions and just used this but I'm so the gently caress confused on what the "lesson" is of it all http://askpython.com/functions/
|
# ? Sep 14, 2015 18:51 |
|
Functions work like stored procedures in SQL*. You pass in arguments (or not) and they do something that's hopefully related to their name and return a value (or not). *I think you said in the general thread that you had some SQL experience, if not ignore that sentence I guess
|
# ? Sep 14, 2015 18:55 |
|
It seems to me like that web page is designed to explain Pythn 3 to people who are already familiar with programming. Anyway: 1. Why would you want to define this function sum? The reason is, if you want to add up a list of numbers in multiple parts of your program, you'd have to make a separate for loop every single place you wanted to do that, and it's better to write that code once, in a function. 2. How does it work? The function definition defines how to compute sum(x), for some value x. Inside the little world where the function executes, it makes the variable list equal to whatever the function's parameter was. Then the body of the function is run. It uses a local variable unfortunately named "sum", which might be confusing because it coincidentally is the name of the function. We could pick a different name instead: code:
|
# ? Sep 14, 2015 19:00 |
|
Veskit posted:Sorry, Your sum() function takes a list as a parameter - you 'pass it in'. That's what you're doing at the bottom in your main code - you create a list of numbers, and pass it into sum. Sum returns some result, which is what gets printed by the print() function (it gets passed in in the same way) So what does the sum() function actually do? Well, you defined it up at the top! You pass something in (you're calling it list), and then you iterate over each element in that sequence, adding 1 to your sum each time. Then you return that total as the result
|
# ? Sep 14, 2015 19:00 |
|
Veskit posted:OK so if anyone has time for a stupid question, I can't wrap my head for how something like this works. I was doing this exercise on for loops and definitions and I can't for the life of me figure out the importance of this exercise. Doesn't having mylist =[numbers] negate the whole function? If you remove it won't this run until infinity? I'm so over functions. Just remember, a function is simply a group of commands that can be run elsewhere in your code. You define a function so you don't have to keep typing that same set of instructions repeatedly. Your code basically goes like this: Set mylist to [1,2,3,4,5] Pass Mylist into the function sum() which was defined above. Within sum: Receive a variable (In this case [1,2,3,4,5]) and call it 'list'. Step over each item of the list, and add each element to the variable 'sum'. This will only run 5 times (as that is how many items are in your list). return the sum variable back outside of the function print the returned information. As for the infinite loop part, you may possible be confusing for and while. For will only do x number of loops (A range or a list for example). While will continue to loop until the while condition is no longer to. (while number < 50: number += 1 #this will run until the variable 'number' is greater than 50, then the while loop will break).
|
# ? Sep 14, 2015 19:06 |
|
It's also unfortunate because "sum" is already a builtin function in python. If you remove the def it will still do the same thing which could be confusing. Building on on sarehu's advice, you should test with this codePython code:
|
# ? Sep 14, 2015 19:08 |
|
sarehu posted:It uses a local variable unfortunately named "sum", which might be confusing because it coincidentally is the name of the function. We could pick a different name instead: Jewel posted:It's also unfortunate because "sum" is already a builtin function in python. If you remove the def it will still do the same thing which could be confusing. Building on on sarehu's advice, you should test with this code THIS, WHY DID THEY DO THIS, WHY IN GODS NAME DID THEY DO THIS So you make the definition, and if you call that definition it'll then run it, and pass it back into wherever you define it. BUT FOR SOME GOD FORSAKEN REASON THEY USED THE WORD SUM JUST TO CONFUSE THE EVER LIVING gently caress OUT OF ME code:
code:
That makes way more sense thanks everyone for the help you're all good teachers and don't make me feel too dumb Veskit fucked around with this message at 19:24 on Sep 14, 2015 |
# ? Sep 14, 2015 19:20 |
|
Veskit posted:BUT FOR SOME GOD FORSAKEN REASON THEY USED THE WORD SUM JUST TO CONFUSE THE EVER LIVING gently caress OUT OF ME Let me introduce you to some Java tutorials. Sum sum = new Sum()? You can think of it like this - there's a function called max() that takes two numbers* and returns the largest one. So wherever you call that function, it'll be replaced by the result when you run the program. This could be super useful if you want to find lots of largest numbers, or if it's a common task that's useful in all kinds of programs (which is why it's part fo the standard library, it's a useful utility). That's how you use it, but how does it actually work? Well, you define the function by giving it a name and listing some parameters it'll use, and then you write some code that takes those variables and does something with them, and comes up with an answer. A function is just a mini program, and it's a way of handling a task separately and neatly, so you can get the result you want without cluttering up your code with the implementation details, or reinventing the wheel. You don't have to use them, but they can be a nice organisational tool - and at some point you're going to find yourself retyping basically the same code at another point in your program. That's when it's a good idea to break that functionality out, and just say 'do thing with X and Y' *it can do more than two and they don't even have to be numbers! Another cool thing about functions, you can make them general and versatile, so you can just go 'hey give me the biggest thing', and the details of how that happens are squirreled elsewhere baka kaba fucked around with this message at 19:43 on Sep 14, 2015 |
# ? Sep 14, 2015 19:40 |
|
http://continuum.io/blog/python35 -To use Python 3.5 in Anaconda, use a conda environment: code:
|
# ? Sep 14, 2015 21:28 |
|
Dominoes posted:http://continuum.io/blog/python35 Kick rear end, thanks. I think setting up an environment is the better way to go anyway, until I'm sure I want 3.5 as the default.
|
# ? Sep 14, 2015 21:35 |
I'm new to Python and I just finished writing my first assembler for an exercise, complete with symbol lookup table. I've never done (serious) text processing before so I feel like I've learned a lot. Here's a simplified version of what I did to get the necessary tokens:code:
Everything works fine but I was wondering if there's perhaps a way to skip the filter step? Using re.split() generates a lot of empty entries at different locations depending on the line I feed it.
|
|
# ? Sep 14, 2015 22:43 |
|
Veskit posted:BUT FOR SOME GOD FORSAKEN REASON THEY USED THE WORD SUM JUST TO CONFUSE THE EVER LIVING gently caress OUT OF ME
|
# ? Sep 14, 2015 22:44 |
|
Ekster posted:I'm new to Python and I just finished writing my first assembler for an exercise, complete with symbol lookup table. I've never done (serious) text processing before so I feel like I've learned a lot. Here's a simplified version of what I did to get the necessary tokens: What's the expression look like? You can probably add capture groups to make getting just the parts you want as easy as tokenList.group('name') as seen in https://docs.python.org/3.4/library/re.html#re.match.group
|
# ? Sep 14, 2015 22:52 |
Munkeymon posted:What's the expression look like? You can probably add capture groups to make getting just the parts you want as easy as tokenList.group('name') as seen in https://docs.python.org/3.4/library/re.html#re.match.group '[@()=;\s]' The problem is pretty much \s in practice. EDIT: Looks like capture groups is what I want, I'll look into it. Thanks! Ekster fucked around with this message at 23:04 on Sep 14, 2015 |
|
# ? Sep 14, 2015 22:59 |
|
KICK BAMA KICK posted:Doesn't cause a problem here but calling the parameter of that function list is basically the same error -- that's the name of the built-in type. People have actually come in this thread with bugs caused by overwriting a name like that. I've had issues naming something list1. For parameters/variables should you not use integers to help label them?
|
# ? Sep 14, 2015 23:06 |
|
Veskit posted:I've had issues naming something list1. For parameters/variables should you not use integers to help label them? Python code:
Dominoes fucked around with this message at 23:21 on Sep 14, 2015 |
# ? Sep 14, 2015 23:17 |
|
duck monster posted:I still havent evolved from 2.7 yet. I probably should update my thinking. async seems to be the selling point to my line of thinking. OpenCV just got official Python 3 support in June of this year. There's enough big legacy projects out there that still require 2.7, and I haven't run in to anything that explicitly requires 3 yet. Async sounds interesting though.
|
# ? Sep 15, 2015 00:27 |
|
Veskit posted:I've had issues naming something list1. For parameters/variables should you not use integers to help label them? What issue? I use variable1/2/3 all the time (or list_1, list_2, list3 and never had a problem).
|
# ? Sep 15, 2015 00:34 |
|
Yeah you can't lead with a digit in a name but anywhere else should be fine.
|
# ? Sep 15, 2015 00:56 |
|
Thermopyle posted:You can use MyPy to check types for you. I know MyPy exists, but it'd be even nicer to have something blessed in CPython that says This Is An Okay Thing. Python's obviously survived a quarter century (jfc) without it, but it'd be a nice-to-have thing.
|
# ? Sep 15, 2015 01:06 |
|
duck monster posted:I still havent evolved from 2.7 yet. I probably should update my thinking. async seems to be the selling point to my line of thinking. 3.5 for me is the point where using python 3 and rewriting in python 3 seem like a good choice. I dunno if this is true for other people (i do unix plumbing stuff bolting api calls to syscalls). It's not just the asyncio stuff, it's also the performance improvements over 2.7, and little things like bytestring formatting operations. The third party libraries i rely on are there too! venvs and pips are finally part of the batteries.
|
# ? Sep 15, 2015 02:58 |
|
|
# ? May 9, 2024 04:45 |
|
Hadlock posted:OpenCV just got official Python 3 support in June of this year. There's enough big legacy projects out there that still require 2.7, and I haven't run in to anything that explicitly requires 3 yet. Async sounds interesting though. Bingo. OpenCV has been one of my big dependencies, it's just so loving useful and fast for image processing that there's little reason to use anything else. Opencv is still not part of Anaconda Python 3.4, and I suspect it's a big part of why Enthought hasn't bothered producing a version of Canopy with Python 3.X
|
# ? Sep 15, 2015 06:56 |