« first day (3713 days earlier)      last day (1226 days later) » 

1:47 AM
@inspectorG4dget Which pun? I don't see any pun.
 
 
2 hours later…
3:39 AM
if you didn't get the joke, you're the joke
just kidding, don't mind me
 
user13727121
is there a way to run a script using the Python terminal? I was able to run it using the command prompt, but I keep getting File "<stdin>", line 1 if I try to run it in the Python terminal
 
user13727121
I tried to save the file in Notepad++, but when I open it using the mentioned text editor, it displays some incomprehensible texts to me
 
user13727121
didn't work, tried it
 
that's weird, I tried it and it worked >_>
 
user13727121
3:55 AM
it returns the same error to me
 
user13727121
$       £:`vç[%ç[%ç[%t–%æ[%üÆ¥%Æ[%üƤ%‘[%üƐ%î[%î#%â[%ç[%¹[%üÆ %æ[%üÆ”%æ[%üÆ“%æ[%Richç[%        PE  d† }'ý\        ð " 
  ì   ®      È6        @                          u…  @                                            . <      ¤P                 l  0                                               ¸                          .text   îê      ì                    `.rdata  è7      8   ð              @  @.data   „@   @     (             @  À.pdata          <             @  @.rsrc   ¤P      R   H             @  @.reloc  J         
 
user13727121
these are the codes presented to me when I try to edit it in Notepoad++
 
user13727121
nevermind, i think i'll just keep learning Python through an IDE before learning the interpreter
 
4:11 AM
@cs95 I didn't see any pun... Must be all the immersion in cold 8º fjord water.
 
4:55 AM
cbg all. What to do with this ancient question on benchmarking bytecode compilation, asked around 2013, presumably about ~2.7.4?
2
Q: How much of a speedup does bytecode compilation give Python code?

Juno WoodsI searched around for a while and have found a number of reasonable claims that CPython's compilation allows faster execution of Python code. I was wondering, though, if anyone knows of any benchmarks demonstrating the degree of the speedup. Alternatively, perhaps there's an easy way for me to b...

 
@smci hammered, thanks for the edit!
 
5:27 AM
? 'unclear'? Am I being unreasonable or is this an XY question asking how to abuse OO without giving any reasons? Python design pattern: class that returns different objects depending on parameters
This one's a blast from the past (2011), that was eventually closed this year. The indictment is a base class master with a classmethod foo(), a child class slaveClass, a grandchild class slaveInstance (yes, really) that tries to override foo() as an instance method. It, umm, assigns slaveType = slaveClass in order to call slaveType.foo() on an instance of the grandchild....
... "Get the whole Java/C++ experience without even needing to write Java/C++..."
 
6:07 AM
Still cant understand why SO has no badges for number of times closing a question :0
 
 
2 hours later…
8:11 AM
@CoolCloud every badge seems to inspire a subset of people to do whatever it says on the label without trying to understand the reason; you really don't want these people on a closing spree
 
8:29 AM
@tripleee Well that is true, but I dont think someone with 3000+ rep would do something like this. I mean there is badge for flagging and for a Q to close, 2 more people have to agree to it.
Though a logical like explanation would be a closed post can be reopened which might lead to instability in the number of closed post by a user?
 
@CoolCloud you'd be surprised
the metrics for reputation etc already have to take into account the fact that some posts are deleted; basically, if it was old enough when it was deleted, you get to keep your rep
 
@tripleee Well I never knew this, I get alot of user removed and minus rep.
Maybe they could adopt something same for cv badge too
 
I'm sure it has been proposed a number of times before; you should be able to find posts about this on meta
 
I guys ... I'm trying to open a office 365 xlsx with openpyxl
but I get this error:
Traceback (most recent call last):
File "./test.py", line 5, in <module>
book = openpyxl.load_workbook('Maping-20.0.5.xlsx')
File "/usr/lib/python2.7/dist-packages/openpyxl/reader/excel.py", line 233, in load_workbook
parser.parse()
File "/usr/lib/python2.7/dist-packages/openpyxl/reader/worksheet.py", line 104, in parse
dispatcher[tag_name](element)
File "/usr/lib/python2.7/dist-packages/openpyxl/reader/worksheet.py", line 293, in parse_data_validation
 
is there a reason you are using Python 2?
 
8:41 AM
Ok I'll try with python3
 
@louigi600 Did you search the site? I found this
 
@louigi600 probably won't solve the problem but more likely to get you to a place where others are willing and able to help
 
get very much the same thing:
Traceback (most recent call last):
File "./test.py", line 5, in <module>
book = openpyxl.load_workbook('Maping-20.0.5.xlsx')
File "/usr/lib/python3/dist-packages/openpyxl/reader/excel.py", line 233, in load_workbook
parser.parse()
File "/usr/lib/python3/dist-packages/openpyxl/reader/worksheet.py", line 104, in parse
dispatcher[tag_name](element)
File "/usr/lib/python3/dist-packages/openpyxl/reader/worksheet.py", line 293, in parse_data_validation
dv = DataValidation.from_tree(node)
tried to save it in xls format but that's not supported at all by openpyxl
 
9:24 AM
@Mikhail You can use a dict for __slots__ if you feel like it. Not sure if any type checker understands that, though.
 
Hi, how to use np.array with cv2 functions ? This code results in error:img = np.array([[[1,2,4]]])
cv2.subtract(img, 1)
Traceback (most recent call last):
File "<string>", line 1, in <module>
cv2.error: OpenCV(4.4.0) C:\Users\appveyor\AppData\Local\Temp\1\pip-req-build-nxx381if\opencv\modules\core\src\arithm.cpp:671: error: (-215:Assertion failed) type2 == CV_64F && (sz2.height == 1 || sz2.height == 4) in function 'cv::arithm_op'
and if i change array to: img = np.array([[[1,2,4],[1,2,4],[1,2,4],[1,2,4],[1,2,4]]]) then it works correctly
 
9:40 AM
cbg, is there a shorter way to do this? I want a list of 2-tuples
>>> a, b, c, d = '1 2 3 4'.split()
>>> [(a, b), (c, d)]
[('1', '2'), ('3', '4')]
is it possible to directly unpack to that list?
 
@python_learner you mean like list(map(lambda x: x.split(), re.findall(r'(\d+ \d+)', '1 2 3 4')))?
 
rolls off the tongue
 
(gets a list of lists, not a list of tuples; obviously not less complex than your temp variables)
 
you don't need list if you unpack it
and I think the right-hand side was just an example
 
laurel, that is what I want but kinda overkill to use regex?
 
9:48 AM
ab, cd = zip(*[iter('1 2 3 4'.split())] * 2)
 
there are various recipes available to get pairs from iterables.
 
the RHS will always be space separated integers (as string)
 
Bottom line: just use what you already have because that's readable
 
I have seen what you said used to convert a list to matrix
 
If by "matrix" you mean "list of lists", sure. If you mean "numpy array", then it was wrong.
 
9:51 AM
[(a, next(b)) for b in [iter(seq)] for a in b]
 
yeah a 2d list
 
@MisterMiyagi excellent use case for an asspression
 
tried it, didn't work :(
[(a, next(b)) for a in b:=iter(seq)] is a SyntaxError. :=
 
(b:= ... )
 
SyntaxError: assignment expression cannot be used in a comprehension iterable expression
 
9:54 AM
oooh
good!
 
should the chat be worked on too much to support code execution? discord lets you run code in chat
 
I want to see just "SyntaxError: assignment expression cannot be used" in a future version of Python!
 
@MisterMiyagi heh
@python_learner no. And it does?
 
@python_learner Code execution is one of those ideas that become more and more terrible the more you think about it.
 
I mean, the discord python server lets you run some snippets, I have seen people showing how to use itertools, maybe its a bot that does that
 
9:56 AM
@python_learner probably
 
it says something like eval job completed, been a while since I was last there
 
they wrote a sandbox for it: github.com/python-discord/snekbox
anyway, stackoverflow chat had a feature freeze about 10 years ago, so there is only the slimmest of chances to get something like that over here.
 
"The hottest Python community on the planet!" I wouldnt call it that
 
10:48 AM
# SysLogHandler
slh = SysLogHandler(facility=SysLogHandler.LOG_DAEMON, address='/dev/log')
slh.setFormatter(formatter)
root_logger.addHandler(slh)
Where it writes the log in case of SysLogHandler?
address='/dev/log' -mens it writes log to /dev/log folder or file?
 
Hello everyone I need help in converting this code snippet from python 2 into python 3. The problem is it uses modules that were in Python 2 but we are using Python 3. Please help if you can or direct me to some appropriate links. MCVE link: pastebin.com/4epgvzgZ
 
@owgitt The SysLogHandler writes to the... syslog. Which that is depends on your system. The meaning of the address is described in the docs.
 
@RaphX It would be simpler to use requests instead
 
11:13 AM
is this ok? pastebin.com/pnWEVeKw @holdenweb
 
@MisterMiyagi How can I access the syslog on Ubuntu?
Sorry. I don't know how this syslog works.
 
@owgitt I recommend to google it.
 
good point
 
I only do MacOS and CentOS these days.
 
Sam
11:33 AM
I'm writing some unit tests on a function which is wrapped with a decorator. I've came across this answer which I think makes sense: https://stackoverflow.com/a/41206923/5173968

The issue is however, my `func` requires reference to `self` as I'm dealing in classes.

I've made up a minimal example to reproduce the issues I am having https://repl.it/join/buhqhsgw-sammm123

My ultimate goal is to unit test `SimpleClass.wrapped_function` in isolation

Any help would be appreciated.
 
@Sam Just so that you are aware: Your code link requires a login and doesn't accept my commonly used auth method. This might affect others as well. Consider to use a different means for sharing code.
 
Sam
Ah man! repl.it used to be good. Thanks for the heads up, I'll chuck it somewhere else now
@MisterMiyagi dpaste.com/FAYG8WSY5 this any good?
 
@MisterMiyagi the link has "join" in the name which is suspicious
 
Sam
@AndrasDeak I think they've recently moved to a login system. It used to be open
 
@Sam You can always pass in self explicitly, e.g. print(x.wrapped_function.__wrapped_fn(x, simple_payload))
To invoke the usual method mechanism, invoke the descriptor explicitly: print(x.wrapped_function.__wrapped_fn.__get__(x, type(x))(simple_payload))
 
Sam
11:44 AM
@MisterMiyagi Ahh I see, that makes sense
 
Be aware that @wraps should already store the original function on the decorator. There is no need for __wrapped_fn.
"this function automatically adds a __wrapped__ attribute to the wrapper that refers to the function being wrapped."
There's also inspect.unwrap if you do not want to remember/hardcode the special name.
 
cabbage
 
Sam
12:00 PM
@MisterMiyagi I did just stumble onto __wrapped__. Saves me modifying the implementation code. Thanks for your help @MisterMiyagi
 
__wrapped__ is one of those things I rediscover every few months. ^^
 
Sam
It's a nice method to know
 
12:21 PM
Plus - there's generally a lot of things "wrapped" this time of year :p
 
12:46 PM
@RaphX If it works, it's OK ;-) but if you read the docs it's much easier to pass URL arguments as a dict. pythonexamples.org/python-requests-send-parameters-in-url should give you the idea.
 
# SysLogHandler
slh = SysLogHandler(address='/dev/log')
slh.setFormatter(formatter)
root_logger.addHandler(slh)


logging = root_logger
logging.info("started")
Running this piece of code on Ubuntu.
Googled a lot
It looks it has to write logs to file - /var/log/syslog
But this file is always empty.
What I am doing wrong here?
 
@owgitt you set up your logger such that info doesn't log. Try logging.error("started").
side note: calling your logger logging is a bad idea
 
1:02 PM
tried the same. No luck :(
 
well your code (with some removals) doesn't log anything on my debian, but changing to .error does, into /var/log/syslog
 
1:16 PM
@owgitt Consider to try this with a regular file or stream handler.
 
1:40 PM
morning cabbages, folks
 
1:53 PM
Cbg, G4dg
 
how goes the battle?
 
Offloading responsibilities like a mad thing in preparation for my new role after the hols!
 
who's the overly excited junior who gets more responsibilities now?
 
Sadly, not happening. One of the devops team who's been around a while will be leading the team, but three of its existing members (besides me) are shipping out to other teams. We're expanding like mad at present.
 
gasp! Good luck
 
1:59 PM
I know. And I'm going to be responsible for recruitment, compensation and professional development for about 40 people. Gulp!
 
does holenCorp exist anywhere in North America?
 
Not that "responsible" is a word that most people would use about me ...
Yes, there's a Boston Office. But development is largely remote.
 
@MisterMiyagi It works fine for file and stream handler.
 
@holdenweb Nice! I like Boston. The roads leave much to be wanted, but it's a nice city
 
Hey people! I've a small doubt regarding sep...
#Taking input from user
n = int(input())

#Printing output
n_range = range(1, n+1, 2)

for x in n_range:
    print(x, sep = ',', end = " ")
 
2:06 PM
sep only matters when you pass more than one positional argument to print
 
In the output, commas are not printed..
 
try print(*n_range, sep=',')
 
@AndrasDeak I'm sorry. I didn't get you.
 
print(1,3,5, sep=',')
 
@RandomPerson print(a, sep=',') doesn't use sep, ^ that does
 
2:07 PM
print(*range(1, n+1, 2), sep=',')
 
@AndrasDeak oh...
 
@RandomPerson also a small style note that will greatly help your code's readability (and it's easy to learn it right when you are told of this early): you should leave out the space around the = in keyword arguments. So print(x, sep=','), but n = int(input()) is fine as-is (because the whitespace is needed in assignments).
 
Whitespace is needed in assignments? I never knew that.
Anyway, thanks for the suggestion!
 
"needed"? no
"preferred, for readability"? yees
 
@RandomPerson "needed" as in "it's good form". It doesn't matter for syntax :) You were using that right.
sorry for phrasing it sloppily
 
2:11 PM
@AndrasDeak ok..
@AndrasDeak It's ok!
BTW, can you share any related documentation (about asterisk)?
 
218
Q: proper name for python * operator?

AnycornWhat is the correct name for operator *, as in function(*args)? unpack, unzip, something else?

anyone know the min rep requirements for answering a protected question?
 
@inspectorG4dget see /help/privileges
 
@inspectorG4dget Thanks!
 
@AndrasDeak thanks. I'm just a little peeved a t some n00b beginner who answered my the-one-question incorrectly
 
BTW, I want to add spaces in the output after commas...
 
2:18 PM
Protect is useless against noobs. Only stops spammers.
 
print(*n_range, sep=',', end=" ")
 
Add it to the sep: print(*n_range, sep=', ', end=" ")
 
@RandomPerson so add a space after the comma ;)
 
But the command didn't work.. what did I do wrong?
What does end do?
 
@RandomPerson read the docs :)
 
2:19 PM
ok..
 
help(print) might suffice interactively
 
@RandomPerson "The command did not work" has little diagnostic value. HOW didn't it work?
 
@inspectorG4dget This worked :)
 
normally, when you print something, the "cursor" goes to the next line, because whatever you print is followed by a newline (\n). This is in fact the default value for end in print. You can set a different default value (like end='|'), which will cause whatever you pnt to appear on screen, plus a |, but no newline. In fact, you may not even see anything on screen (depending on whether you're running this in the REPL), and that's because of how flush works (read the docs)
 
When I try this..
print("Numbers", *n_range, sep=", ")
there is comma after "numbers" argument. I don't want that to happen. Is there any way to avoid that?
 
2:26 PM
you'll need two calls to print, then
 
2:43 PM
@RandomPerson eventually, you'll come across someone who'll tell you to do this: print(f"Numbers: {', '.join(map(str, n_range))}"). Resist the urge to do that. While it does have its place, its a bad habit that leads to unmaintainable code
 
@AndrasDeak I recently forced myself to do what you said not to do :/, glad I can stop it
 
@python_learner see python.org/dev/peps/pep-0008/… and PEP 8 in general
 
@inspectorG4dget ok.
 
3:03 PM
I need to look into that, I guess the only thing I follow that is snake_case and the 80 line limit
 
can anyone help me with a flask deployment with nginx and uwsgi? My question is posted here: stackoverflow.com/questions/65308170/…
 
I started coding python in 2007 and fell in love at first byte. I love the language and couldn't imagine a life without it. But if there's one thing I hate about it's, it's goram snake_case
I'd much rather camelCase, but that's just me being lazy
 
@python_learner the 80 limit is the one that most people ignore most of the time :)
 
most of the youtube videos I watched when I started out used camelCase and I guess this is because they were all java turned python "devs"
 
Yeah. See also class Solution: code challenge sites, ugh
 
3:07 PM
I only do that for college assignments, you get penalized else :D , yeah that is something I learnt was bad after seeing the comments here
 
3:22 PM
@RandomPerson happy medium between multiple print calls and f string / map wackiness: print("Numbers:", ", ".join(str(x) for x in n_range))
 
i want to make a fast way to control my raspberry pi robot currently i am flask to send requests via web and control it but the latency is too much is there any faster method
 
usb cable?
 
it has to be wireless
i am using a flask server right now so if i need to make it move forward it is like <ip:port>/forward
but the http requests using flask are slow
 
How about sockets
 
How about gpiozero?
 
3:37 PM
Yeah I was going to recommend pypi.org/project/flask-io
for websockets with flask
 
I'm not convinced that flask is necessary at all, as long as you're willing to craft your bytes by hand
No HTTP, we TCP/IP like men
Then again I have no practical experience with the rPi
 
Nice thing about gpiozero is you can direct it from non-raspi Unix clients (macos, linux)
 
Independently of whether you use flask or flask websockets or sockets etc, I wonder if it would be possible to establish a WLAN with just your desktop and your robot. I suspect it would be a smidgen faster than using a wireless access point as a middleman
That's like, one less network hop, think of the savings
dozens of picoseconds at the least
 
@Kevin by Grabthar's Hammer
 
I like holdenweb's gpiozero suggestion, consider this an additional vote for it
 
3:47 PM
Streaming Advent of Code day 15! twitch.tv/davidism
 
@AndrasDeak [the sigh of a classically trained actor reduced to local car dealer commercials]
 
i will explain my problem in depth and also why i cant directly control gpio pins , so i made this raspberry pi zero w 2 wheel car so what i do i connect it to my wifi network then through gpio pins i run the motors but the problem is every command take few
mil secs to happen like i when i say left the motors spin and the after few mili secs left happen so for now i was using flask web server so i just have to make a http req like in this format <ip:portof my rpi>/command like forward backward and all but now as
flask is Asynchronous in nature let say if i previous command takes 800ms to complete and then i send another command it justs queue and after the first command implementation it implements which drives car crazy i want something faster
 
As im fairly new to this community, what does faded out answers mean? Like this one here, the answer is faded out, unless we hover mouse over it.
 
I still think wifi is slowing things down, definitely think about that WLAN thing I suggested
@CoolCloud It has a negative score, so it's probably not a good answer
 
kevin i totally agree with you but the main issue is i want to make requests Asynchronous so it doesnt take like 800ms to complete it just send the request and quit
 
3:52 PM
@Kevin So answers with lot of -ves will be faded out?
 
@Kevin current i broke and i cant use anything like nrf or something so i have to use this for the moment
@CoolCloud yes the people think that this question isnt helpful or silly or any other reason thats why its downvoted and hence the light colour
 
I thought rPis could be configured to be an ad hoc access point out of the box, but if you have to buy an adapter or something to do that, nevermind
 
@VineetKumarGupta Hmmm, cool feature ;) The irony that it is the accepted answer too xp
 
@Kevin it can be but the thing is i run it wirelessly and headlessly so its mounted on the bot and now if i need to program it i just ssh into it through wifi now i have set the wireless credentials so i would have to change it by modifying the contents of boot and as well as wifi router gives more range for my car :0
 
It's strange to me that the pin library doesn't seem to be asynchronous... If I had free time, I'd poke through the documentation to see if there's some way to send a command and not wait for a response
But alas, my work's QA server is on fire and I have to put it out. No time for reading.
 
3:58 PM
@VineetKumarGupta So does this flask server run on the Pi, and you use a PC web browser to send it commands?
 
@holdenweb yes
 
If so, you could relatively easily make the flask server respond by a) triggering a separate thread to run the command, and b) returning an imediate response to the web client, perhaps?
 
for eg
@app.route("/f")
def forward():
global last
last =1
GPIO.output(17, GPIO.HIGH)
GPIO.output(27, GPIO.LOW)
GPIO.output(23, GPIO.HIGH)
GPIO.output(24, GPIO.LOW)
sleep(0.8)
GPIO.output(17, GPIO.LOW)
GPIO.output(27, GPIO.LOW)
GPIO.output(23, GPIO.LOW)
GPIO.output(24, GPIO.LOW)
return ('', 204)
this code would take 0.8 sec to run till then my control commands are useless
think of an 800ms lag in control
 
So run them in a thread.
 
@holdenweb can you just give an eg to run them in thread for this case
i havent used threading in flask or python so i dont have any idea
 
4:08 PM
To a first approximation:
import threading

    ...

app.route("/f")
def forward():
    threading.Thread(target=do_forward).start()
    return "", 204

def do_forward():
    global last
    last =1
    GPIO.output(17, GPIO.HIGH)
    GPIO.output(27, GPIO.LOW)
    GPIO.output(23, GPIO.HIGH)
    GPIO.output(24, GPIO.LOW)
    sleep(0.8)
    GPIO.output(17, GPIO.LOW)
    GPIO.output(27, GPIO.LOW)
    GPIO.output(23, GPIO.LOW)
    GPIO.output(24, GPIO.LOW)
So the web client gets an immediate return and the do_forward function runs the action in parallel.
I'd advise you to do without the flask server altogether if you are using a computer to run the browser, but that will do for some experimentation.
 
[socket library intensifies]
 
4:31 PM
@holdenweb thank you it works like charm , i have one more question how can i make a push button like till the moment i have pressing a button in the web page the function should run the moment i leave it stops . like a toy rc car forward button . is it possible with flask
@Kevin thank you kevin , bruh you also helped me a lot i will surely look into sockets and stuff as an initial understanding i think it might be very low on cpu and simple which is a very big pro in case of single board low power comp like rpi
 
That would be a bit more complicated (unless one of the many smart people here can prove me wrong). The web page on your browser would have to send a start command on mouseDown and a stop command on mouseUp. This would mean programming in Javascript. The techniques are fairly well known, but it turns it into a complex multi-component system.
 
I continue to agree with holdenweb
 
The requests fro the browser would have to be asynchronous (i.e. sent and received without refreshing the displayed page). If you want to research the techniques, look at AJAX, but I'd not recommend that path for a beginner.
 
I think Flask, or one of its extensions, has decent websocket support
Or, hmm
Might be overkill if ajax suffices
 
I'd recommend using the gpioZero package. This would (IIUC) allow you to write Python programs on your laptop that could remotely control the RaspberryPi's GPIOs. It must surely be worth a look?
 
4:39 PM
If I read the convo correctly, he tried but it had a lot of latency
"i connect it to my wifi network then through gpio pins i run the motors but the problem is every command take few mil secs to happen"
 
i am actually trying to just make it simple that why i just make this like a simple get request kind of thing , i downloded a http shortcut app on my android device and i maped all the commands and put the widget on my home screen so now i just have to connect to the network and press the widget and boom my bot moves
 
On second read, he never says that he tried gpioZero specifically
 
@Kevin yes i never did but it would have latency as the gpio would have to engage for a few mili sec and it kind complex as i would have to rewrite
but thanks to you smart people here the latency is almost nill now it works fine
 
How are you controlling the wheels now? Is there some way to talk to them without gpio?
 
yes i actually used an l298n motor driver and 2 motors for each tyre if
i want to rotate the car i run them in difffrent directions
 
4:45 PM
hmm, neat
 
l298n is controlled by gpio's
i am able to make it run for like 20km/s without much difficulty in controlling
 
Hi everyone!
After looking at numerous questions, I couldn't answer the following:
Is there a real internal technical difference between a post and get request, or are they just semantic identifiers which subsequently cause technical differences?
 
as with faster speed response time reduces
 
I don't totally understand your setup but if you're happy that's good
 
@Kevin thank you mate
 
4:46 PM
at least you got there in the end davidism :)
 
@aeyalcinoglu I believe that according to the spec, GET requests can't have a body. But in reality... who knows
 
Everything is just semantic identifiers except the electrons going through the chips ;-)
 
haha, the amount of just doing things slightly wrong for today's AoC was awful
couldn't figure out an optimization either, but mine completed in about 30 seconds
 
I enjoyed it though - I'm glad I'm not the only one that has those days :p
 
the only reason my code looks so good in Flask, etc is because I spend hours working on it. More people need to watch my stream and see that it's not like that normally :-)
 
4:55 PM
I must learn davidism's secret technique of writing code that gets better the more one works on it
The more I work on my code, the uglier it gets
 
Thanks for the help people! Bye!
 
@Aran-Fey If I'm reading tools.ietf.org/html/rfc7231#section-4.3.1 properly, get requests typically don't have a body, and servers are free to reject get requests with a body, but the specification doesn't forbid a body
Of course, sometimes "technically allowed by the specs" means "rejected by 100% of real machines because they couldn't be bothered to support it"
 
5:10 PM
i have been there first time and let me tell you , you guys are the real saviour lots of respect , actually ++respect :)
 
5:51 PM
how do I convert a string '0110' to binary number in python? I tried bin(int('0110')) but it still returns a string
 
int('0110', 2)
 
yeah sorry I missed that

    # convert string to int
    num = int(N, 2)

    # convert int to binary
    binary_num = bin(num)
 
what is your definition of a "binary number"? what do you expect to happen?
 
however when I try and check if the result is even or odd using & operator I get an error
if binary_num & 1 == 1:
 
try that with N instead
 
5:54 PM
but it's not an integer, it's a str and they don't support &...
 
This is why binary operators should be implemented on bytes rather than int. Change my mind.
 
so theres no actual binary type in python?
 
Pretty sure there's no binary type in most languages
 
numbers are just numbers
 
Is there a name for the way integers are represented in (binary) memory? I know there's some IEEE spec for floats, but I've never heard of something similar for ints
 
6:02 PM
if you try to reduce a number '011100' to zero using either subtract one or division by two, (depending if its odd or even) why is using shift operator faster than actual division when the number gets really huge?
 
Anyway, when you use a bitwise operator like &, you're basically saying "Take these two integers, imagine they're each represented as a series of bits, create the bitwise AND of these two bit series, and interpret the resulting bit sequence as an integer"
 
i coded my solution using division operator so number / 2 however i think the efficient implementation would use number >> 1
 
it might help if you explained what you're trying to do...
 
number / 2 is true division (can return a float). number // 2 should be exactly as fast as number >> 1, at least assuming a semi-decent optimizer
 
given a number like 28, keep performing an operation on it (subtract 1 if odd, or divide by 2 if even) until you get zero
wait so //is faster than / ?
 
6:05 PM
yes
although we're in the realm of micro-optimizations here
Every time I call something a "micro-optimization", I secretly hope that there's a random C programmer listening in and getting their socks blown off. Anyone else?
 
interesting I timed it and >> takes less than half the time // takes
that's significant
 
Significant compared to what?
 
Oh, I guess the optimizer can't replace // 2 with >> 1 unless it's 100% sure that the left-hand operand is an integer
 
when I use // by 2, on huge number I get around 0.05711674690246582 ms but when I switch to >> 1 I get 0.022000789642333984
the calculation was on the above starting from a really huge number (too big to post here)chat.stackoverflow.com/transcript/message/51161810#51161810
 
6:20 PM
normally when integer division is your bottleneck you shouldn't be using python
 
anyway it was coding assessment problem
I'm not sure if I was able to switch languages between questions
 
@Kevin I suspect that's the absence of any asynchronous execution mechanism on the RasPi.
 
@erotavlas if the coding assessment problem times out it won't help if you optimise integer division
 
@VineetKumarGupta gpiozero allows very fine timings, but if any of your commands involves a wait of any kind you must run asynchronously or resign yourself to doing things one at a time ...
@Kevin Stop choosing gnarly problems?
 
@AndrasDeak the closest solution I could find to the problem was this one, they are manipulating the string array to shift the bits manually to simulate the shift operator, at least I think thats what they are doing geeksforgeeks.org/…
is that more efficient than doing the integer division? I'm going to try it out later on
 
6:30 PM
@Aran-Fey Surprising how many optimisations look really good until you get to the corner cases.
 
Bit operations in python are weird. How the heck does this happen?
>>> (-3) >> 1
-2
>>> bin(-3)
'-0b11'
>>> bin(-2)
'-0b10'
I would've thought right-shifting -0b11 would turn it into -0b1
 
Something something two's complement?
I never understood what that meant so it's a perfect scapegoat for weird binary things
 
Hmm, I'm not sure if two's complement can be used for integers that can grow infinitely large/small
 
7:04 PM
Not sure how that works still.
 
ah, so basically the bin output is weird for negative numbers. -3 looks like -0b11 but is actually 11111101
Whoever thought it was a good idea to implement bitwise operators on numbers was a potato
 
Well yes. Subtract one from zero you get -1 or ....11111111 - as many leading ones as the length of the representation you're using. Subtract two from that you get ....11111101.
bin cheats by putting a minus sign before the representation of the positive equivalent.
 
7:33 PM
I've built decision trees and neural networks for classification. Is it possible to change the algorithms to do regression? If so, how?
Is there a better chatroom to ask? Can I post this as a question?
 
8:06 PM
Has anyone here tried to build and/or maintain an OOP project using Cython? I'm trying to decide on a scale of 1-to-insane how viable this is but it's not easy to gauge just how much overhead it would be and whether the whole thing collapses on complex OOP problems
 
8:28 PM
huh, it seems that the python bindings from ZeroMQ do just that so it's at least viable
 
I saw a cdef class earlier today on a mailing list, but I didn't want to share remote anecdotal evidence
 
That's fair enough :) It at least answers my question of whether projects can successfully use that approach, but it doesn't help gauge the trade-off (I figure that the transpiler can only be so smart and then the complexity of the system means you'll just get diminishing returns)
I have a feeling after a meeting tomorrow I'm going to have to make a snap decision between Cython or Julia and might not have a chance to go back. It's likely we'll need a POC where a central requirement will be handling requests at a silly scale (as opposed to the logic) but I don't think there's a common language other than Python across the potential team :/
 
8:53 PM
Oh man. I'd only just scanned that code originally but I just found this code comment and its credibility is immediately thrown into question :P
 

« first day (3713 days earlier)      last day (1226 days later) »