« first day (4201 days earlier)      last day (748 days later) » 

12:04 AM
PyCharm - it'll charm you with the amount of memory it hogs on.
 
 
6 hours later…
Wes
6:34 AM
is there any accepted style for giving type hints more user friendly names?

remote_computer_ip=str
remote_computer_name=str

dict[remote_computer_ip, remote_computer_name]
 
I'm not sure I understand. What could be more user-friendly than the type itself? I don't follow your example code
 
Wes
7:03 AM
person = tuple[str, str, int, int] # no idea what's the type parameter names
name = str
surname = str
age = int
cats_owned = int
person = tuple[name, surname, age, cats_owned]
(i have no idea if that's the correct syntax for tuple type hints)
looks like i should be using NewType
 
It isn't the correct syntax for type hints. But "name" is not a type (the type is string, so str)
The syntax you're using just assigns each of the names to the primitive types, which is not useful at all
 
Wes
so how do you differentiate between tuple[name, surname] and tuple[surname, name], since both name and surname are strings?
 
7:21 AM
You have a number of different options:
import math
from collections import namedtuple

# Type-hinting a variable
name: str = "roganjosh"
print(name)

# Storing named data in a dictionary
person = {
    'first_name': 'rogan',
    'surname': 'josh',
    'age': math.inf,
    'cats_owned': 1
}

# Using a named tuple
person = namedtuple('Person', 'first_name surname age cats_owned')
this_person = person(first_name='rogan', surname='josh', age=math.inf, cats_owned=1)
print(this_person)
Fundamentally, a regular tuple isn't the kind of structure you want for this. You could just make a Person class too, and store the data as attributes for that class. However, this doesn't have anything to do with typing because you're talking about names. The type doesn't give you any information about the specific data beyond the object type e.g. str or int or dict or MyCustomObject etc.
 
7:43 AM
@Wes Use an alias if the types are equivalent, such as Vector3D = tuple[float, float, float]. Use a NewType if the type has additional meaning, such as URL vs. str.
 
Wes
8:15 AM
if i can use person = namedtuple(...) in a type hint then it's cool
btw, shouldn't Person be ucfirst, given that it is a class?
 
Yes it should
 
Wes
unless there is a way to provide just one argument without having to rewrite the whole list of parameters twice?
 
Like def f(*args, **kwargs): super().f(*args, 'foo', **kwargs)?
 
8:38 AM
@Wes perhaps in paid pycharm
 
Wes
8:50 AM
@Aran-Fey ah, not too bad
@AndrasDeak--СлаваУкраїні ¬__¬
 
 
4 hours later…
1:19 PM
It's 2022 and today I struggled to assign a value to a boolean. Why? Because for some reason, the devs decided to condense 11 different booleans into one int of bitwise flags
 
I didn't know you switched to C
 
I didn't, which is worse, in a way. In C I would have access to the 11 constants that let you access each bit by name, but of course nobody bothered to make those accessible from python
It's such a stupid idea, I can't even
 
1:36 PM
I'm sure there's a handy helper somewhere in the API :P
Or you're not supposed to change that, making it your fault #wontfix
 
2:06 PM
perhaps there are 10 million copies of these flags which would justify not using an 11-length dict
 
Nah. Most programs will only have 1 copy. And since it's written in C, it's much smaller than a dict. Probably just 11 bytes, not sure what data type C uses for booleans
Although, there is some overhead because this is actually a higher-level abstraction of a property. Changing the value emits an event and stuff like that
 
Well I meant a literal dict. Arguably you wouldn't want to juggle 11 bool flags around.
 
Then again, it would be nicer if each boolean had its own event...
Oh, they're properties of an instance
 
numpy's bool is 1 byte and that probably comes from C (on typical systems)
@Aran-Fey but then how can you not see them independently? You mean the unified 11-bit thing is a single property, right?
 
Yeah, that's what I meant
 
2:17 PM
I thought we'd gone back to the discussions of every different type of inf being implemented, only in the context of bools :P
 
I'm just wondering if I'd opt for a single dict as the property that contains all 11 flags as keys. Probably a needless indirection, but 11 bool flags dumped into the API might also not be great. Doesn't really matter either way, because both are hypotheticals.
 
 
1 hour later…
3:26 PM
@Aran-Fey In C, it's pretty standard to put a bunch of boolean flags into a single int, and manipulate them with bitwise operators. If you want to give the bits names, you can use #define constants, or an enum. C also provides a bitfield struct mechanism to define named bitfields, which can be 1 or more bits wide.
 
I think he probably knows all (or most) of that
2 hours ago, by Aran-Fey
I didn't, which is worse, in a way. In C I would have access to the 11 constants that let you access each bit by name, but of course nobody bothered to make those accessible from python
 
Yeah, the part I don't know is why it's common
 
If I understand correctly he'd grudgingly accept being able to do mask |= lib.flags.FROBNICATE
or... something like that which actually works
 
Well, it's reasonably fast and it saves space. Sure, RAM is a lot cheaper now than when C was created, but it's still useful to pack stuff as single bits for storage, plenty of file formats do that.
 
It's actually more complicated than that. What should've been a simple foo = bar, is now a flags = (flags & ~(1<<FOO)) | ((1<<FOO) * bar)
 
3:31 PM
And is FOO documented at least?
 
...in the C documentation, yes
 
Ok, it's a bit verbose & messy to read.. In C, you'd hidecthe messiness with a couple of macros.
 
Is this by any chance a C library with a thin and potentially autogenerated Python wrapper?
 
Admittedly, bitwise stuff is a bit painful in Python, partly because we no longer have a fixed sized basic integer type, and we don't have unsigned ints. Unless you're using Numpy.
 
3:35 PM
@AndrasDeak--СлаваУкраїні Thin no, autogenerated (I think) yes. It's fairly pythonic, just poorly documented
 
@Aran-Fey Also consider using ^ to toggle bits.
 
I know, but I'm setting, not toggling
 
Fair enough.
 
4:22 PM
That (1<<FOO) expression has me worried that FOO and the other flag constants are defined as consecutive integers. It's much easier when they're powers of two instead.
 
Well, either convention works, as long as it's clear which convention you're using. :) It's fairly common to have two parallel sets of names, one set for the bit numbers, one for the powers of two. IIRC, X windows does that.
 
flags |= FOO        #set field to 1
flags &= ~FOO       #set field to 0
flags ^= FOO        #toggle field
if flags & FOO: ... #query truthiness of field
If memory serves correctly. And it should work even on Python's weird always-signed variable-sized ints
(confidence that I have not overlooked a corner case: 80%)
 
Yep. For some things in Python, you need to AND with an appropriately sized mask of 1 bits.
 
I have txt file full with this 12-14-08-10 number pattern. How I can calculate it. I know how to read from a file but I don't know how to separate number and add. I need to get 44 or 12+14+08+10 Can someone help me with that?
 
>>> line = "12-14-08-10"
>>> line.split("-")
['12', '14', '08', '10']
>>> [int(x) for x in line.split("-")]
[12, 14, 8, 10]
>>> sum(int(x) for x in line.split("-"))
44
 
4:35 PM
Jan 5 at 9:14, by PM 2Ring
Here's a more extensive demo of using bitmasks to do unsigned arithmetic. It calculates the SHA-1 hash. https://gist.github.com/PM2Ring/63be1b6f43c77c3b36b19d4190400215#file-sha1_demo-py
 
@Kevin Thank you Kevin
 
:-)
It bothers me that I can't do b"foo" & b"bar"
They're bytes, and bytes are made of bits, and bits are born to be ANDed together. Let me AND together my bytes, Python
 
@pijes A few days ago I posted you some links about making permutations. Were they helpful? Or was my code too complicated for you?
 
@PM2Ring I've already finished that. It was probably complicated. For me, most of these things are complicated. Thank you again if I didn't thank you.
 
@Kevin I agree. Of course, you can just convert the bytes to int, or to Numpy arrays. But it'd be nice if bytes supported bitwise ops.
 
4:40 PM
The public demands it!
 
@Pijes No worries.
Courtesy of robjohn in the Math chat:
 
Relatable
 
4:56 PM
Am I right in thinking that commits from "gitname" are from people that didn't fill out their credentials properly when they did their first commit? And, if so, is there a way to block this? Searching "gitname" has a lot of pollution and I'm half guessing about how this comes about in the first place
This is what's showing up in the commit history, or have they deliberately just set their own display name as "gitname"?
 
@roganjosh sounds like something that depends on the git server too
a commit can have arbitrary authors (name, email), and how that gets mapped to a user registered on the server is probably non-trivial
I'd first check git log locally and see what that commit really looks like
git show <commit hash> should probably show the header too
 
Sounds good, thanks. At least I'm not missing some fundamental feature. I'll raise it with our engineering team when I'm officially back in because it's bugging me with it being across multiple repos
I had a couple of ideas on how it arises and all of them suck in terms of accountability
 
5:12 PM
It probably won't help your server, but if those commits have reasonable e-mail addresses (just inaccurate ones) you could use a mailmap file to make git show proper aliases when looking at logs locally. Git servers often don't support this feature though.
 
Everyone that works on my direct projects always has a name associated with their commits, it's just when I wander into other projects that it starts to grate on me. In other words; our server should almost certainly be able to do things correctly going forwards at the very least, and I can probably live with it not being backdated. I just don't know where this hole in identification comes from
 
It's probably that the person doing the pushing is not the same person (in terms of credentials) who made the commit. Otherwise the server would link the commit author through the submitter.
My best bet would be an ill-configured setup where someone makes commits with bad credentials. Private e-mail for instance. Looking at the commit should tell you that.
 
Hmm, that would be interesting. Ok, I'll give it a shot
 
The alternative I can think of is someone in the team not having an account with the remote server, and yet getting commits pushed. Since you normally share commits through the remote server this is unlikely.
 
Hmmm
commit 521... (HEAD -> wf2_moving, origin/wf2_moving)
Author: gitname <gitemail>
Date:   Sun Apr 17 13:05:52 2022 +0100
 
5:19 PM
nice
I doubt that the server would use that as a placeholder (my guess would be that it should at least have an @ in the fake email address). So probably someone's local git setup uses those placeholder credentials.
 
I'm guessing that the credentials don't throw a fit if you just enter empty strings instead of your name and email address. In any case, it's not my problem to fix, I can just kick up a fuss about it as long as I'm not being dumb
 
the person who has this setup (assuming this is the problem) probably doesn't even know about it
ask them to check if git config --get-regexp 'user\.*' looks like they expect it to (within the offending repo)
and by "them" I mean "everyone on that team"
 
Could be one of 80 people, and I'm pretty sure there's more than 1 person. I'm willing to accept that they probably didn't deliberately hide their identity, but we shouldn't be allowing them to commit (IMO) and that would also raise the flag for them to get it fixed
 
Yeah, especially if thete are multiple people
 
5:44 PM
I wonder if you could track ip addresses, or some other mostly-distinct identifier. More to tell all the gitname users apart than to track down their true identities
 
Maybe. I'm really only interested in fixing it going forwards; I need to know who's getting an 11pm message of "So, I was just browsing your stuff and things and, well, WHAT THE HELL?!"
... Not quite that bad :P
 
6:16 PM
@Kevin for the person doing the pushing yes, looking at logs on the remote server. But committers need not be pushers, especially since commits can have arbitrary credentials.
If one of these gitname's is the owner of a commit at the tip of a PR branch then they were probably the ones pushing too.
 
It's possible that we have some kind of release pipeline that I don't understand, too. I'll dig into it but it'll be at least a week before I get an answer
IOW maybe the commits come from git itself as part of CI or something. I don't know enough
 
6:39 PM
@roganjosh I doubt it. In any sane system these would be attributed to obvious bot accounts. In any case it's not that hard to spot human-made commits.
 
I doubt it too, but there's a lot that goes on that's nebulous and hidden from us pesky data scientists, so I'll keep an open mind. The company recently migrated all of their backend libraries out of my sight
Oh well, I'll pick it up and report back (assuming I remember for a week!). I'm on holiday so naturally I'm pottering around building things in new languages to relax
 
 
1 hour later…
7:44 PM
Can I ask you something again. I read with this code my data file but I get one line with text and one line blank but in file I have only lines with data text. I tried many code from internet but nothing work pastebin.com/9kGEX6ET
 
@Pijes You need to try the code that does "read each line from a file".
 
I almost never use readline. I either iterate directly over the lines using for line in file: or I get the whole file in one string with foobar = file.read()
 
@AndrasDeak--СлаваУкраїні yes they read all but add one blank line after each line
 
I looked up how open handles newlines and I don't see a way how that could possibly happen. So my guess is that the problem is actually somewhere else
 
7:51 PM
Here is a proper MCVE that I put together in one minute. Pijes, please provide something like this next time.
 
@Aran-Fey Yes, this method worked for me many times.
 
Of particular note: the output does not contain "Line one"
 
@Kevin Uff, I think I now understand the problem...
Each line ends with a newline character, and print adds another one. So you see empty lines in the output.
In other words, you're reading the lines correctly, you're just printing them wrong
 
So I need to add "\n" somewhere. Is that correct?
 
Adding more "\n" to your print call will only add additional blank lines
 
8:00 PM
Well they said "somewhere". Inside .strip is "somewhere".
 
This is only a problem if you print the lines anyway. Surely that's not really what your code does with them, is it?
 
print(line, end ='\n') I tried this but not work
@Aran-Fey No I print it only for test.
 
Why did you try it? (Not a trick question or rhetorical question, I really want to hear your thought process)
I worry that you're trying random things that involve the "\n" character, already knowing it probably won't work, in the hopes that one of us will say "well, you put in an effort" and we'll give you a complete working solution. I think it will be better for you in the long run if you puzzle it out yourself
 
I have numbers like this in file 20-22-03-13. I need to calculate numbers. You help me with that today. So I wanted to read it from file and calculate with your code
 
For example, you should be able to understand and explain why print(line, end="\n") seems to behave identically to print(line), just by looking at help(print)
There's no obscure unwritten minutae here, it's all in the docs
 
8:07 PM
I swear this code has read the file many times properly. I honestly don't lie to you.
 
I believe you. I often have code that works fine for a long time, and then suddenly, it's not fine.
 
As I've already explained, there's nothing wrong with the way you read the file
 
I partially agree. In many use cases, it doesn't really matter if your line strings have a newline on the end. Whatever processing you do to the lines in the next step might simply ignore them. For example, if you feed them into an re.match call.
Or if you pass them to int, for example:
>>> lines = ["1\n", "2\n", "3\n"]
>>> [int(x) for x in lines]
[1, 2, 3]
>>> sum(int(x) for x in lines)
6
 
OK. Thank you. I will try
 
(We still need to figure out why "Line one" isn't in the output of my MCVE, but, one thing at a time.)
 
8:17 PM
@Kevin Line one exist but line two doesn't.
 
@Kevin No, don't. Just replace the readline() stuff with for line in file. Problem solved, if it even was a problem to begin with
 
@Pijes In your code, maybe. In my MCVE, I plainly see "Line two" in the output, and no "Line one"
@Aran-Fey I'd be fine with that, but the conversation kept going after I suggested for line in file: half an hour ago, so I'm assuming that approach has been rejected for some reason
 
@Kevin No I tried but probably made some mistake. I will try again
AttributeError: '_io.TextIOWrapper' object has no attribute 'line'
 
If it doesn't exist, don't try accessing it.
You seem to be doing f.line.
 
@AndrasDeak--СлаваУкраїні Yes I tried with line in file but not work
 
Interesting. Let's see an MCVE.
 
with open('data.txt') as f:
for line in f:
line = [line.replace(' ', '') for lines in line]
print(line)
With this I get '19-14-12-10\n' So yes thee is /n problem
 
Well, besides the missing indentation, it looks syntactically valid to me.
 
I assume trying to get chat code formatting to work would be too ambitious
 
Oof, that's a lot of line
 
8:27 PM
we should let Kevin's kid gloves handle this
 
line = [line.replace(' ', '') for lines in line] is not valid
 
@Pijes I don't believe that that is the complete and full output of your code. The only thing you're printing is a list, so your output must have square brackets.
 
@Kevin If I understand you no. I get only numbers in first example and with /n in another
 
Here is what I see. Certainly the output contains the string '19-14-12-10\n' , but that's about 2% of the total output.
 
8:31 PM
@AndrasDeak--СлаваУкраїні fair. I'm gonna back out. There's enough people on this
 
I'm amazed you guys are willingly going off on tangents
 
Have you noticed that the MCVEs I'm linking to provide clear and incontrovertible proof that the output I'm claiming to see, is really being produced by the code I'm claiming to run? If you get tired of people saying they don't believe you, MCVEs are a great way to put a stop to it.
 
@Kevin Not sure but I think you wanted this pastebin.com/yXHcTQBd
 
Why is the data in a .py file?
 
@roganjosh That's without reason. Because I have data.txt so I name it like that.
 
8:44 PM
The extension doesn't really matter, as you can read it as text, but something now tells me that you made that file and introduced all the newlines programmatically
 
@roganjosh Probably. I use Notepad ++
 
"Probably"? You either did or didn't get code to write that data to a file
 
Not sure. Use part python for that.
I don't have a lot of mental capacity. I'm struggling to survive. I'm not as smart as you. I'm not smart as an average programmer either. I have this problem of quick forgetting. I also write tutorials for myself, which I follow later.
 
That doesn't make any sense. Did you, or did you not, create "F:\Python\data.py" from your own code?
 
Did ================ RESTART come from REPL or Python IDLE?
 
8:49 PM
@roganjosh No. I just write it
Yes I restarted because Kevin wanted just 2%
 
@Pijes we completely understand that, and we sympathise. But recently you've been coming with various problems fairly frequently, you often ignore people responding to you, and demonstrate too many missing spots in your understanding. We can help to an extent, but if you don't pull your weight then the regulars here will lose all their remaining patience and the help will stop. This is just a hint of a warning for now, so you know what's at stake.
 
@AndrasDeak--СлаваУкраїні I can't do better than this. But I understand you. You really helped me a lot of times.I never ignored anyone. I just can't always understand you.
 
Honestly, I'm on the edge now. I'll continue tomorrow. Thank you all for your help.
 
8:59 PM
Never think that one day I will not repay you if I am able.
 
@Pijes You owe me (us) nothing. If you want to repay us, focus on improving your asking and responding here. Make sure you understand what we're saying, and keep asking what we mean until you really understand.
Otherwise we're just wasting time, yourself included.
 
9:26 PM
OK. i didn't really go i just lost the internet. Now it came back to me again. I hope you understand that I am still preparing when I need to ask you something like going to an interview at the US Embassy.
I just have a problem with both language and dyslexia, for a long time as a child I didn't know where the left is and where the right is. If I didn't write with my right hand, I wouldn't know that today. On top of all that, I was burdened with a life that I could not even imagine as a child.
I know it all sounds like an excuse to you, but it's not. I have frequent ocular headaches and at that moment I can't see anything for 45 minutes. I am now at the age when I can neither see with glasses up close nor can I do without them. When I look at a laptop screen I have to have them. When I take my cell phones, I have to take them off. In a word, I am a failed case that is still going on. Cheers to all.
 
@Pijes it needs to be made clear to you that people in this room have a whole backstory themselves. We accept people as they come and how they interact with the room. That defines the person; not their difficulties outside of this room
 
@Pijes I'm very sorry to hear that. I don't think anyone doubts your difficulties. But we've seen you struggle for almost two years now, and it's becoming clear that we can't help you help yourself on this timescale. We keep fixing whatever problem you run into at the time, and often you're stuck again on the basics. When this happens too frequently it becomes problematic, because the people who volunteer their time here will end up frustrated and find other ways to spend their time.
The only thing I can recommend is for you to try and spend more time working on your own before responding to a next round of help. For instance when you were told that the issue was a trailing newline, you jumped head-first into a random solution attempt that had no basis or reason. This is what gets frustrating for us. You shouldn't rush yourself. You can take what time you need: this chat has a persistent history we can reply back to.
 
10:00 PM
I know you all have problems in life. I fully understand. Can I get a ban by the end of 2022 but that in 2023 we can hang out again. Until then, I will try to learn the language better. And how to ask a question.
"For instance when you were told that the issue was a trailing newline, you jumped head-first into a random solution attempt that had no basis or reason." - I just wanted to show you that I'm really trying to solve the problem.
I did not mean anything bad.
I just want you to know that I really appreciate you helping me for so long. Cheers
 
"Can I get a ban by the end of 2022 but that in 2023 we can hang out again." I don't know what you mean. We are not banning you; you can moderate yourself and get what you need from the chat room?
FWIW Andras and I can't ban you from the room. We can kick you to the point that a moderator takes notice (and other things). or you just take responsibility for your own journey and take peoples' advice on board, and drop the backstory
 
But before we start kicking you we'll explicitly ask you to stop asking for help here, so you'll notice (we're not there yet).
 
10:35 PM
That's nothing to do with python
 
ok sorry, i got it to work anyway
 
Within 2 mins of posting the off-topic question?
 
yes , i read the message xD, there was '#' next to the command and I didn't notice until I read my own message lol
 
While I can see the lighter side of that, had I kept that question around, it would be taking up people's time to figure that out for you. It needn't really have been asked in the first place
 
yes i appologize, i thought of everything that could possibly be making that and there was a very small slight chance that python was involved somehow, so out of desperation I just through it out there hoping for any hint, but as soon as I read my own message , I removed the "#" and tested out and it worked lol

you did the right thing, I apologize
 

« first day (4201 days earlier)      last day (748 days later) »