« first day (3755 days earlier)      last day (1176 days later) » 

12:00 AM
@AndrasDeak Yeah, so basically the solution was to manually create the union in the __init__.py. Every day we stray further from Guido van Rossum's light.
Also strikethrough doesn't work in chat?
 
it does, with ---
you can practice in the sandbox
1 message moved to Sandbox
 
1:11 AM
this one might be obvious, but is there any way to run this:
print >>output, "wello horld"
in python3?
 
@NordineLotfi are you asking how to print to a file?
 
found the use of >> with print a lot, but most of them was with py2
@AndrasDeak no, i already know how to do that :)
 
So what are you asking?
 
was just wondering how to make that specific code above work, the one using >> with print, but in py3
since just adding () doesn't work
 
Yes, you can't make a syntax error valid. What are you trying to ask?
It's almost as if syntax changed between python 2 and 3.
 
1:13 AM
nvm, i guess this one works instead
print('Filename:', filename, file=f)
 
Which is, "how to print to a file", yes?
 
@AndrasDeak was just curious about the >> part, really
@AndrasDeak yes, and i already know how to do that as previously stated
 
hence my confusion
 
was just, and really just curious about the use of >> in py3
@AndrasDeak my bad
 
you use it for bit shifting
 
1:14 AM
@AndrasDeak oh, i only ever used ^, guess there more operators i didn't try yet
 
Brace yourself because you also won't be able to use backticks and <> in python 3
 
@AndrasDeak yeah, got a couple nice script i need to move over to py3
thankfully nothing too huge
 
Most of the conversion can be done with the 2to3 tool. Tricky things start with string handling.
 
btw, can anyone explain to me how a encoding spec work? a specific one I'm trying to implement in python, but i don't understand the whole thing
 
Why do you have scripts in 2? I thought you started recently with python. Who trapped you?
 
1:16 AM
@AndrasDeak lol, myself?
I had a couple scripts i was using previously before i started learning python "seriously". but now that I'm learning, i kind of have to port them now
 
@NordineLotfi I can see why that got downvoted. It's not clear at all what you're asking. You seem to be asking "How do I implement <thing>, because I couldn't find a python implementation?". Normally you look up the algorithm. If that fails you might try looking at some implementation, trying to figure out what that does. But that's a lot more difficult and error-prone usually.
 
@AndrasDeak but there not even a single working implementation, i searched before i asked!
the only one that exist publicly is made in netrexx, but it seems to not work for some reason
I do understand, like half of it, but can't wrap my head around the letters used in the spec
and afaik, no one made any implementation of that encoding on github either...at least the search result didn't come up with anything (tried many keywords)
 
Did you find Hertz's patent?
this seems to be the relevant paper dl.acm.org/doi/abs/10.1145/360569.360660
 
@AndrasDeak I only looked at Chen-Ho patent/paper. didn't thought of looking at the similar other implementation yet
@AndrasDeak thanks, will look into it
 
You... looked at the paper. Do they not explain what...the paper is meant to explain?
Again I'm confused about what you're asking then.
Wikipedia page seems extensive too for that matter.
 
1:28 AM
the one i looked at (for Chen-Ho) yes, it did. But as i said previously, i only understood like half of it, but didn't understand *the rest* _because_ of the letters used.

eg: I can't seem to imagine what the output would look like on an example string like 23456 etc
 
OK, looking at the wiki page this seems straightforward enough
(Assumptions follow.) The boldface letters are placeholders for "any binary digit". The ones and zeros are fixed, slicing out a subdomain in the binary pattern.
 
@AndrasDeak OH, so they're just placeholders. That does clear a bit of the confusion yeah
I was unsure if they were either placeholders or actual possible output
 
it all makes sense if they are placeholders
 
indeed!
 
0abc 0def: abc and def with binary triples encode 7*7 things
100c 0def encode 2*7 things
and the placeholder picture works in the sense that the four rows don't overlap
and it all seems to be about encoding pairs of decimal digits as binary digits
 
1:36 AM
@AndrasDeak I see :D
@AndrasDeak yeah, that part was already understood at the start
@AndrasDeak Thanks, i think i got it now. Will try to grind a bit more and make a toy implementation
 
1:54 AM
@AndrasDeak it's not a syntax error fwiw.
 
@alkasm it isn't? I thought it was one too given it would result in a syntax error if used in py3 afaik
 
>>> print(>>'potato', "wello horld")
  File "<stdin>", line 1
    print(>>'potato', "wello horld")
          ^
SyntaxError: invalid syntax
 
No but it raises a custom error message
 
oh
I see
 
Yeah if you put a parenthesis
>>> print >>output, "wello horld"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for >>: 'builtin_function_or_method' and 'str'. Did you mean "print(<message>, file=<output_stream>)"?
 
1:57 AM
>>> print 'potato'
  File "<stdin>", line 1
    print 'potato'
          ^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print('potato')?
the interpreter is just too smart for its own good
 
it's just hideously special cased for this
 
@alkasm but fair enough, I see how it's not a syntax error in this weird edge case
 
yeah. you can actually make this work right? replace print with a custom version that implements rshift and takes in a file
oh I guess the comma operator would make that call and then the string as a tuple so it wouldn't be called with args or anything useful
so i guess not
maybe you can abuse frames
:|
 
@alkasm what you said remind me of this: github.com/seperman/bad-ideas
there some interesting stuff there, like pipe implementation that i wanted to make
 
lol import bad
 
 
1 hour later…
3:10 AM
I got my first gold badge, 100 consecutive visits
 
 
5 hours later…
8:37 AM
10 hours ago, by Andras Deak
@LutaayaHuzaifahIdris hello. Please don't ask for help here with fresh questions on the main site as per our rules.
 
 
1 hour later…
9:43 AM
Cbg all, I was preparing myself for a programming competition and was wondering is it better to raise error or rather print out a message ?
 
print if you want to talk to the user (i.e. the person sitting in front of the PC, using your program), raise if you want to talk to the programmer
 
Nah I dont think I should be talking to the programmer, as the judges will just be users right?
 
consider to raise at the site of the error, then to catch and report the error at an outer layer dedicated to talking with the user.
if there is no such outer layer, that's the sign that you should not just print the error.
 
What do you mean by outer layer?
You mean like logs or stuff?
 
the function calling the function calling ... the function that encounters an error.
 
9:47 AM
@CoolCloud Right, the programmer in this case are you. If you want to catch and handle the error, raise it. If you want to tell the user that something went wrong, print it.
 
Oh I see, maybe I shouldnt print out the error, just a message will do :)
 
But as MM said, if you choose to print it, make sure to do it from an appropriate place
 
@Aran-Fey Yes that will do, thanks
 
You might get extra marks by offering the option to print debugging information, in a way that clearly explains the user probably doesn't need it unless they are a developer? Or perhaps condition the debugging information on some DEBUG flag that the regular users wouldn't set.
 
Maybe check out multi-tier architecture. The idea is to separate the code into one part that's responsible for the business logic, one part that's responsible for the user interface, etc
 
10:44 AM
Hi
Is anyone online at this time?
 
Yes, why not? I think this is not Usa only zone
 
right
 
I might not answer your questions but you should go ahead and shot your question, there are people who monitor here time to time
 
I need a bit of help with python.
i'm trying to read some image data in order to generate a pallet for it in the form of a dictionary, i'm trying to remove all duplicates of colors in it expect one. But i seem to get an error.

`RuntimeError: dictionary changed size during iteration`

https://paste.pythondiscord.com/alafolatub.sql
 
11:00 AM
You should describe your goal, because it seems that you're creating random 8-character names for your colors and praying that no duplicate name is ever created
The final palette should look like... what?
 
{aklsjf:'255 102 2', ashdd:'31 201 2', ashjd:'100 0 25', ...
with no duplicate values in the keys
 
dont modify containers while iterating over them. a dictionary already has unique keys, so your requirement isnt very clear to me from your statement
but if you meant to say, no duplicate values, but you dont care about the total number of items in the dict, then you could always simply create your dict, then create a reverse of this dict (aka values become keys, keys become values) That operation will get rid of value-dupes.
 
oh
well, i guess that could work
yup, it does
 
11:34 AM
I really have no idea what you even need those keys for, but if you really need keys, why not just use an incrementing number?
 
oh
 
@ParitoshSingh that's the problem, the keys are randomly generated... so if you generate a duplicate, you end up overwriting something you shouldn't have overwritten...
So what do you need this dict for? Why do you need to map each color to a meaningless key?
 
oh
i dont even need the keys
sorry, im just very tired it's 1PM and i havent gotten any sleep since yesterday \
oh and also, i'm trying to make a compression algorithm for an image format i made
 
11:55 AM
Has anybody ever written Python code for catching signals from the OS?
 
Like with signal.signal? Sometimes
 
@Aran-Fey Good advice on basic separation of concerns.
 
yes, just wondering what one would use them for?
Just in general, you know.
 
If you've written a daemon process in Python, you might want to process the HUP signal and interpret it as "re-read your configuration file and continue operations." That's a fairly common requirement.
[daemon = run\s in background, detached from any console].
 
@holdenweb cool, thanks. What would typically send the sighup signal in this case?
 
12:11 PM
The admin who's reconfigured the daemon.
kill HUP pid being the operative command IIRC.
 
ok cool, thanks. I've used atexit before in Python, but didn't realise that it's like a wrapper around catching the KeyboardInterrupt exception raised by a sigint signal.
 
@Sect0r I don't normally correct the English of non-natives, but this tripped me up for a bit: you need a "palette". A pallet is this :)
 
oh, i'm sorry haha
 
absolutely no worries, just thought it might help going forward
 
thanks
 
12:24 PM
@jigglypuff i think you may be on the wrong track there. What you need to look at is signal handling: docs.python.org/3/library/…
 
@holdenweb I would like to ask you a question, how many hours do you work average for a workday? I mean efficient hours?
 
See if the example towards the bottom makes sense.
The usual strategy is to have your signal handler set a flag that the other logic examines periodically.
@Alper Between seven and nine, normally—thought I don't stop thinking about work just because I step away from my desk, so I allow some of that as working time too. Why do you ask?
 
I'm trying to decipher this text:
Note: The functions registered via this module are not called when the program is killed by a signal not handled by Python, when a Python fatal internal error is detected, or when os._exit() is called.
about atexit, so it can't be used to handle sigint?
 
Asking you because you are very experienced and you are from the USA(guessing). I think America is highly competitive(guessing). I don't think I work very efficiently more than 3-4 hours a day.
 
As I said, you're on the wrong track. atexit is used to register functions that will be called when your program terminates, to allow you to (e.g.) release operating system resources and so on. Simiarly, you register a signal handler (a function to be run when a specific signal is raised). But Python doesn't handle all signals, so the docs are warning you there's nothing you can do about those.
 
12:34 PM
So could I use atexit if I only intend to catch sigint (sent via CTRL + C)?
I guess you can, CTRL + C raises a KeyboardInterrupt
it doesn't send a signal to the program, so atexit will be invoked.
atexit won't handle a sigint sent via kill 2 <pid> though. So in general you'd need both, atexit to handle CTRL + C, and signal to handle kill 2 <pid>
 
1:25 PM
Hi
 
hi
 
I'm running this command:
for i in ${WORKSPACE}/Fixed_Zip/ `find . -name "*.ipynb" -type f`; do
jupytext --to py "$i"
done
 
@Sect0r interested in that if you ever release it somewhere :)
 
@NordineLotfi ?
 
1:27 PM
which means go thought all the subfolders in Fixed_Zip folder and convert all the files of ipynb to py
 
@Sect0r click on the grey arrow to see what i was replying to (in front of my message)
 
but I get this error in jenkins log:
jupytext.paired_paths.InconsistentPath: '/var/lib/jenkins-slave/workspace/10098-detaiku/CICD_for_Bundles/dev/DSS_Infra_Jobs/TEST_FOR_YONI/CI/Fixed_Zip/' is not a notebook
 
Oh,
I'm planning to make a github repo for it in a bit, but i'm a noob at dealing with github stuff so i'm not sure how its gonna turn out ;-;
 
ignore my message
 
Oh! I'm sorry
 
2:11 PM
Does anyone know how to do this: re.findall('\w\n' * 5, string), but without the * operator? I mean like how to use a regex pattern to multiply the \w\n pattern a number of times. Thanks!
 
@AnnZen the pattern (?:\w\n){5} should work.
 
@jigglypuff The fact that CTRL/C raises KeyboardInterruptError is because Python does handle that signal. Whether your signal handler would override the standard one is beyond my knowledge. You do NOT need to use atexit to catch CTRL/C. Simply try ... except KeyboardInterruptError: ... at the appropriate point in your logic.
It seems you still mistake the purpose of atexit, whose registered functions get called whenever the program terminates - even if it calls sys.exit, or simply drops off the end of its logic.
 
(?:...) creates a group without capturing it. {n} means "match n times".
 
@MisterMiyagi Thank you so much!
 
@Nagendra_databee please don't ask for help here with fresh questions on the main site as per our rules. You asked that 7 minutes ago. Maybe wait a bit more to see if you get answers on the main site.
 
2:40 PM
is it ok for questions on main to get 3 upvotes without a code (op didnt post what was tried)?
 
Depends on who's asking, I'd say. Ultimately, code that isn't working isn't adding anything useful to a Q&A pair. So if you trust the OP to have done their homework, they don't necessarily need to include their failed attempts
 
op just pasted input json and output json , felt like "gimme the codez"
 
If it's a low-quality question then 3 upvotes can be suspicious especially if it was asked recently
 
my thoughts exactly, the moment it got a negative score, it was back to 0 (+1, -1) not actual 0
 
how did 3 upvotes turn into +1/-1?
 
2:52 PM
I was solving the question, so I was keep tracking of it from 0, now its at 2 (+3, -1)
before I was going to paste my solution a different user had already pasted it, OP accepted it like less than a minute
felt strange so I didnt bother answering, just left it at that
 
looks at the JSON tag .... puts JSON tag on ignore
Oh my...
 
I am guilty of answering such (JSON) questions but its kinda fun to learn json manipulation
 
Don't feel guilty, SO is already a garbage dump anyway. As long as you're learning something, that's what really matters
 
@python_user that much upvote on SO sounds weird yeah. Even with decent question and failed attempt, i always see either 0 upvote or 1 rarely. (unless the question somehow get high traffic)
 
Well, IMO the only valid JSON+Python questions come down to json.loads/json.dumps and friends. Everything else is regular dict/list/... stuff.
 
3:01 PM
@Aran-Fey makes me feel better :)
 
@Aran-Fey that's also why i used to wish we had a specific SE for python
 
@MisterMiyagi the jsonpath library is kinda cool though :)
 
@JonClements orjson is also nice! Very friendly towards loads/dumps... :)
 
and probably the demjson library for json that's not quite json...
and... I guess the ijson library to stream stupidly large json data dumps
 
Sorry, I'm on a crusade against json that's not quite json. Fix the source, not the reader.
gets his pitchtorch
 
3:05 PM
@MisterMiyagi I kind of hate working with json, especially when trying to scrap specific sites, and they end up changing the json syntax slightly every 1 week or so
then you have to resort to regex instead
 
@MisterMiyagi well... often times I receive files that are JSON - they're not... and it's a bug in their export system they're not in control of... so just have to live with it
 
I've never seen a json file that wasn't valid json O.o How do you even mess that up?
 
The most common error is {key1: "foo", key2: "bar"} and demjson handles that nicely... so it's not exactly a biggy either...
 
Hmm, so some clown probably just took the string representation of a javascript object and called it json?
 
@Aran-Fey tons of proprietary sites/export system do this surprisingly
 
3:09 PM
@JonClements guess there's some advantage in our community writing all our own crap ^^
@Aran-Fey custom JSON dump functions. :/
 
@Aran-Fey I think that's the most likely explanation...
 
I finally have a hypothesis why I prefer " over '. I think it's because I use a swiss german keyboard layout and the ' key is more awkward to press then the " key. Can other german keyboard users confirm this preference? Because universally I see people prefer ' instead of " and I wonder why that is
@JonClements wait what is the issue with this?
 
yeah, ' is a single key press on an english keyboard. Not sure if that's why I prefer it, though
 
@Hakaishin " is [shift]+[2], ' is [shift]+[#] on my Apple German keyboard. So it's pretty much the same.
@Hakaishin keys must be quoted.
 
Well... on a UK layout... to get " it's shift+2, while an ' is a separate key and easy to access with your little finger from the homerow
 
3:13 PM
@Hakaishin I use an European keyboard, but i always use " unless I'm editing a line/lines that need ' for escaping/or other weird cases.
 
I would like them to include this question, like which do you prefer and why in the next SO dev survey, it will be like the spaces vs tabs wars just for zoomers
 
Well... in some languages they're completely different things and not interchangeable anyway... C's ' is only for single characters... and in PHP - they affect if a string gets interpolated or not
 
It's annoying that ' is a common character in english tbh. It's why I use double quotes for error messages and single quotes for everything else
 
@Aran-Fey unpopular opinion: contractions are unprofessional and you shouldn't use them anyway ;)
 
@Aran-Fey why not just use " everywhere for consistency?
@AndrasDeak agreed ;)
 
3:17 PM
@Hakaishin there times when you can't: eg escaping "" etc
 
@AndrasDeak subtle :)
 
@Hakaishin Not sure tbh. Maybe I should
@AndrasDeak You've activated my get-out-of-jail-free card: I'm not a professional ¯\_(ツ)_/¯
 
Ugh Ros got all the style guidelines wrong for python and some for C++. CamelCase whaaat. Hanging intendation how ugly, line length 100, and single quotes over double quotes, meh :D
@NordineLotfi ofc, but that seems less common the @Aran-Fey case
 
@Hakaishin yeah. I don't see myself ever needing this for python but for stuff like shells script, definitely.
 
atleast they got their cmake style guide game on point :)
 
3:32 PM
@Hakaishin I don't get why people have the need to define custom style guides for languages that already have official ones.
In the end it will rely on some public code that follows the official gude.
 
3:54 PM
@MisterMiyagi good point. *Insert standards joke here*
 
@Hakaishin "Microsoft"? p
 
I was thinking more about: xkcd.com/927
 
 
2 hours later…
5:30 PM
@Hakaishin heh... an oldie but a goodie :)
 
Hi all.. hope all are good
can anyone let me know how to run python exe or py file uploaded on google drive
actually i want to make user to run python script that will be uploaded on my google drive from any py file that i will share them. actually i dont want to give my that py script to users that is uploaded on my drive
 
Hallo does anyone use keras model load?
 
 
1 hour later…
7:04 PM
@AndrasDeak You meant "should not use them," naturally.
@Hakaishin There's only one black.Do what black does, kids - better still, integrate black into your commit hooks to program as you like and still use formatting standards.
 
 
4 hours later…
10:45 PM
@Aran-Fey JSON has a lot of variants which are not exactly valid JSON. For e.g. JSON doesn't allow trailing commas nor comments, but both of these variants are supported by a wide variety of parsers. Programs which use JSON for configuring settings often support both of these since lines may be added/deleted at will, leading to potential hanging commas as well as sometimes needing inline docs/explanations
For e.g., my project local .vscode/settings.json supports both and the filetype detected for syntax highlighting is "JSON with Comments"
 
wim
11:44 PM
@PaulMcG Happy New Year - Don't drink and sudo (updated for this CVE-2021, oof...)
9
 
whoopsie
 

« first day (3755 days earlier)      last day (1176 days later) »