« first day (4943 days earlier)      last day (15 days later) » 

9:04 AM
@ThiefMaster i wrote /www first because that folder used to exist in the linux root.
@PM2Ring i'm glad that references work similar at least. both dicts and lists are references..
 
9:55 AM
Everything is a reference.
 
10:06 AM
Is a while loop followed by an else a common / acceptable practice ?
as in

```
while i < 10:
do this...
else:
do that...
```
@AndrasDeak--СлаваУкраїні indeed, i meant, they are the same reference
 
Yes, otherwise the construct wouldn't exist. The question is only where you apply it
 
@MahNeh Acceptable, yes otherwise the syntax wouldn't exist. Common, not really. But being uncommon shouldn't be interpreted as something to avoid.
 
Jinx padlock jinx. 20 Quatloos
 
i guess being brief isn't useful. i mean whether there are gotchas and that's why it seems uncommon
apparently if you break from the while it exits the whole thing. but that's not too unexpected
~actually that's not true I think.~ correct myself again, it was true, bad test.
 
I don't follow this monologue you're having with yourself sorry
 
10:16 AM
you don't have to participate in a monologue, don't worry
 
10:46 AM
@MahNeh As Andras says, everything is a reference in Python.
Since the else clause on a for or while loop is so rare, it's a good idea to comment it when you use it. Especially if there's an else-less if before the loop, or inside the loop.
I've seen code that uses the "loop with else clause" get messed up by well-meaning editors on SO who forgot (or never learned) that loops can have an else clause.
 
@PM2Ring bc it's C under the hood right ? i just mostly referencing that array1=array2 has the same behaviour than in JS/TS, and I assume var_c = var_d won't stay using the same reference and can be updated independently ?
@PM2Ring thanks for the advice
 
@MahNeh because it's how Python was designed.
 
@MahNeh What's under the hood is irrelevant. Sure, CPython is C under the hood. But there are other options. Thinking about Python in terms of C pointers and stuff can be helpful, but it can occasionally be misleading. IMHO, it's best to just embrace the Python datamodel on its own terms. Don't think about putting objects in boxes. Think about putting nametags on objects.
 
Python is not CPython is not C
 
so it's not the difference bw pointers and "standard" variables in C what makes those behaviours but a separate design decision ?
i forgot what i knew about C so i'm using terms vaguely, sorry. i think pointer is the right word though
 
11:01 AM
@MahNeh Forget what you think you know in other languages and read a Python tutorial. Patterns from other languages can mislead you.
 
no, i won't, i like to compare languages. it may be useless at first, but pays off later on usually, and it's fun.
 
It's not fun for those who have to answer corresponding meaningless questions. Like the classic "is Python pass by reference?".
It gets old quick.
 
Language comparison can be illuminating. But you need to know the languages that you're comparing. ;) Trying to learn Python
by mentally translating Python stuff into stuff from other languages is a limited strategy.
It's like learning a human language. If you're continually translating everything in the new language to your mother tongue, it's laborious, and it won't lead to native fluency.
 
fair enough
so as a start i'll consider everything is an object, and so it has a reference
is this an ok starting assumption or still wrong ?
 
That's fine.
Sep 5, 2019 at 6:10, by PM 2Ring
I've been coding for almost 50 years. Most of the languages I used before Python require you to declare the types of variables, so I know how to use that stuff. OTOH, coming to Python was very liberating.
 
11:14 AM
Everything is an object and the only way to do anything with them is if you have a reference
 
i'm reading a post as well
 
"a post"s are usually trash
Even more so since chatgpt
 
@PM2Ring i'm not 50yrs coder but i prefer typed languages so far
 
If it's on SO and highly upvoted it might be fine
PM already pointed you to the names vs variables post, that's most of what you need to know aside from a python tutorial. The official one is fine since you already know other languages.
At least I think he did
Yup.
 
yeah it's a huge post though
i'll take a look
 
It took me a few months of immersion into Python to break myself out of the habit of analysing it in terms of C. And then it finally started to make sense. :) I could do things The Python Way, rather than always writing C-like code in Python syntax.
 
but you use types right ?
type hints
 
@MahNeh heads-up: I refuse to let anyone else here waste their time by spoon-feeding you things you know where to read about.
 
i guess you don't know democracy
it's a practice here in western countries
 
Some use type hints. But some of us prefer to not use them.
I fell in love with Python because it freed me from having to deal with types all the time. And I don't agree that it's a good design strategy to bolt an ad-hoc type system to a duck-type language.
2
 
11:23 AM
@PM2Ring interesting
 
@MahNeh Definitely work through the official Python tutorial. It was written for people who already know how to program (in a C-like language). It's not perfect, but it is excellent. It will give you a very solid foundation.
 
i will, thank you
 
Excellent
Some old examples of for ... else stackoverflow.com/a/39875722/4014959
 
11:43 AM
interesting, i thought it was just for `while`. i have to ask though, if you create the arrays:

```
a = [0,0,0]
x = 0
b = [x,x,x]
```

b takes less memory @PM2Ring ?
 
Generally yes, but in this particular case no because there's always only 1 copy of the number 0
...in CPython
 
interesting, thank you ! @Aran-Fey
could be useful for initialising tensors i guess, when they are filled with say 255
 
23 hours ago, by ThiefMaster
start by not calling them arrays but lists
 
No really because what you're calling "array" is actually a list, and proper processing would use numpy or some other numerical library
 
wouldn't the tensor occupy less space ?
 
11:55 AM
And worrying about memory is not in the tutorial
 
What tensor?
 
if you create a numpy array, for example, or using pytorch
 
If the values go over to a numpy array then they are copied, so I'm not seeing how your questioning fits together
 
Numpy arrays are a bit different because they contain machine integers or floats, not Python number objects. So Numpy arrays are very similar to the arrays you already know from other languages. So don't worry about them right now. Focus on Python's built-in datatypes.
 
i see. thanks. will shut up now or i'll get an ICBM
 
12:03 PM
:)
Python has several built-in array-like datatypes: tuple, list, str, bytearray, bytes, (and memoryview). There's also array.array in the stdlib, although that's very rarely used. In Python, when people use the word "array", they usually mean a Numpy array. So it's a bit confusing to call lists or tuples arrays.
 
Just to follow up on that - it's not that people are splitting hairs about the semantics of "list" vs. "array". They are wildly different objects that behave in completely different ways.
3
 
 
10 hours later…
10:34 PM
Hi, anyone here?
 

« first day (4943 days earlier)      last day (15 days later) »