« first day (2830 days earlier)      last day (2115 days later) » 
01:00 - 20:0020:00 - 22:00

1:01 AM
@abarnert I think your answer to that Python / C question deserves to be the winner.
 
1:12 AM
Please reject this edit, which attempts to correct indentation errors in the question code. stackoverflow.com/review/suggested-edits/20307340 OTOH, the question code is so bad that merely fixing the indentation doesn't change much. ;)
 
1:26 AM
@PM2Ring They're both good answers. Yours gets to the point a lot faster, and also hints at why you'd want this feature in the first place; mine provides more background.
 
@abarnert Thanks! I hope the OP of that primes question you just answered appreciates your work. IMHO, that one screams out for the old "Lacks minimal understanding" close reason. So much bad indentation, severe colon deficiency, and incoherent logic, in only a few lines of code... ;)
 
1:52 AM
The fact that the OP hasn't posted "i tired your code and it gives me error" yet makes me a bit optimistic…
 
 
3 hours later…
4:51 AM
must be "tiresome" to process comments like that
 
 
1 hour later…
6:08 AM
Lint says that
df = pd.DataFrame(
    df.values.repeat(v.str.len(), axis=0), columns=df.columns)
is better than
df = pd.DataFrame(
    df.values.repeat(v.str.len(), axis=0), columns=df.columns
)
 
Looks cleaner to me
 
I agree!
 
What does your linter think about
df = pd.DataFrame \
(
    df.values.repeat(v.str.len(), axis=0), columns=df.columns
)
The clearly superior way to define dataframes
 
6:33 AM
Ew
 
sure
linter hates using `\` to continue lines.
 
So do I
 
7:00 AM
late night cabbage
 
Mid day cabbage :D
 
cbg
 
I need to be up in less than 7 hours and can't seem to fall asleep
 
not sure if that will help, but I'll give it a shot
or else put on a podcast...
 
I have no idea what is said in this song, but this helps me often
 
thanks for the suggestions. I'm sure part of my sleeplessness is due to the bright light shining from my monitor...without any blue filtering
gonna try to get some sleep, rbrb all
 
Morning cbg :(
 
cbg andras
something got you down?
 
7:30 AM
France Won !
 
they did, and quite deservedly
@AndrasDeak maybe this can cheer you up?
 
@Arne morning :(
snek is always appreciated, though
 
@Arne Is that a python with cabbage?
 
it's supposed to, yes =D
 
Very cute.
And the colours are very similar to the python that spent the winter in my garden a few years ago, when I was living near Coffs Harbour. chat.stackoverflow.com/transcript/message/21453404#21453404
 
7:44 AM
nice of that nope rope to be the non-lethal kind
 
@PM2Ring I didn't know non-venomous animals live in Australia as well. Looks pretty cool
 
We have lots of non-venomous animals here. :) It was great having that python in the yard, but unfortunately it left at the end of winter.
 
Did it eat all the venomous marsupials?
 
I think it mostly ate non-native mice and rats.
 
7:55 AM
The banana farmers love it when a python takes up residence in their banana storage shed because that reduces the amount of rats and mice that want to eat the bananas.
AFAIK, there are no marsupials with poison. The male platypus has a poisonous spur on his hind legs, IIRC. But a platypus is a monotreme, not exactly a marsupial. The male echidna also has a spur, but it's not venomous.
I was a little disappointed that today is overcast here. I was hoping to see venus during the daytime. It's fairly bright at the moment and today it's quite close to the (just past) new moon, which makes it easy to locate. Mind you, the moon is a very thin crescent, so it can be a little tricky to spot in the daylight hours.
 
Good day :)
Another day, another great question ;) stackoverflow.com/questions/51357644/…
 
user9455968
@AndrejKesely Indeed. Where do people get ideas like this from?
 
@Lu I don't know, I'm on stackoverflow only one week and already I'm starting to lose faith on humanity :D
@LutzHorn ^
 
user9455968
@AndrejKesely Yes, it is frightening to see all these bad questions coming in.
 
@LutzHorn They say SO is unwelcoming, toxic place...but these questions, my god.
 
user9455968
8:45 AM
@AndrejKesely You are right at the center of the discussion going on for years.
 
user9455968
Sooner or later you crack under the load of all these questions. And since duty calls...
 
@LutzHorn What I think is opposite, stackoverflow IS welcoming place - if somebody would just think one minute before writing the question (that includes formatting at minimum...)
 
user9455968
 
user9455968
@AndrejKesely I totally agree, but tell that to the staff
 
@LutzHorn that's beginner question (I'm ok with that). But yeah, searching around SO before posing the question would help
 
8:51 AM
@AndrejKesely I want to close that question, but I can't think of a close reason that applies to it. I guess I could dupe-hammer it, but that feels like cheating.
 
user9455968
@PM2Ring which question?
 
I'm going to the beach, sunny here in Estonia...so later! :)
 
@AndrejKesely +1
 
9:28 AM
Reminds me of an anectote where someone used a preprocessor to have whilst loops in C... — tobias_k 51 mins ago
^ awesome
 
9:53 AM
If I have a context manager that can throw an exception in its __enter__ method, what's the nicest way to wrap it in a try...except? (Assuming I don't want to wrap the whole with statement in a try block)
import sys

ctx = ContextMgr()
try:
    foo = ctx.__enter__()
except ZeroDivisionError:
    print('caught exception in __enter__')
else:
    try:
        1/0
    finally:
        ctx.__exit__(*sys.exc_info())
^ my current code :/
 
Is Visual Studio Code an ideal IDE for Python? I can't seem to find any information covering this seeming as it is a relatively new editor.
Just getting started with Python and I'm wanting to create a web scraper.
 
Try looking at PyCharm, or Spyder.
Else, there is no "best" IDE. There are only people's preferences.
 
Hi, @IgorV. Welcome to the Python room. If you're looking for alternatives to Learn Python The Hard Way, see our tutorials guide. It's not very big, but it has some good stuff.
 
nvm, I found my answer here
Let's discuss: with blocks should have optional except and else clauses that are executed depending on whether the __enter__ threw an exception or not. Yay or nay?
 
10:10 AM
It should be a nice feature imo.
 
@IgorV. I have no idea why your question got those downvotes. I think your question is well-written. I guess some people might think you didn't do enough prior research. Or they just hate LPTHW. ;) Of course, if your main Python resource is LPTHW then it can be hard to understand why stuff behaves the way it does, especially in the early parts of the book. That's one reason why we don't like LPTHW.
 
You might want to init a flag, and after your with statement, go into an if-statement if the flag hasn't been triggered ?
 
@Aran-Fey Sounds good to me.
OTOH, with blocks are nice because they hide messy details, so ideally you shouldn't even get an exception, and in the case where you do need to know about exceptions the context manager can't adequately deal with then explicit try...except exception handling makes sense.
 
@Aran-Fey A potential problem with that might be that people could assume that __exit__ was called in the handle-blocks, which is not the case.
 
10:25 AM
@PM2Ring What about his approach, method of learning?
@PM2Ring Thank you for the links. I've found criticism of his book very helpful in understanding the difference of 2 and 3, as much as one beginner can.
 
The criticism of Python3 from Learn Python the Hard way is not up-to-date though. Or at least the speed point he's talking about.
 
10:48 AM
Apr 12 '16 at 15:01, by PM 2Ring
@AndrasDeak My guess: people expect it to be some kind of boot-camp style of teaching. And they want that because they respond well to that kind of environment. Zed has the sergeant-major persona down pat, but his boot-camp is not very well-organized, so people don't emerge from it with the skills they expect. He works them hard, but they don't get the rewards they expect from getting pushed hard like that.
 
@PM2Ring This is an interesting one.
 
Admittedly, teaching someone their first programming language is not easy. You have to teach core programming concepts as well as the grammar of the language. It would be nice if you could start with the basics and gradually build up to more complicated stuff, explaining everything as you go, but that's not practical.
And it'd be boring for the students, who want to start writing code that does interesting things. Sometimes you have to say "we need to do X here, and I'll explain what that does later". But LPTHW does that far too much.
 
11:57 AM
Programming guides are more exciting when there's a "there's no time to explain" on every page. It's like you're running from the Terminator.
 
@PM2Ring Good point. Maybe I need to rewrite my context manager so it throws the exception when it's created, not when it's__enter__ed.
@Arne Hmm, you may be right. It's probably not immediately obvious what a with...except...else is supposed to do.
 
12:37 PM
Since contributing to this open source project, I have noticed a 300% increase in unexplainable behavior. I think my presence has tainted the code base.
Not because of my commits, those are fine. It's the miasma of entropy that emanates from my being.
 
DSM
12:50 PM
Monday morning cabbage for all.
 
Rational explanation: now that I have the power to make merge requests, I'm 300% less likely to see unexplainable behavior, think "meh, nothing I could do about that anyway", and immediately forget about it
I didn't start the fire. It was always burning since the world's been turning.
 
DSM
Callbacks: #1, #2, #3. Why yes, I have opinions, would you like some?
 
cbg all
 
Personally I'm disappointed that we haven't gotten an updated version of the song every ten years
Most likely people have tried, but haven't reached the level of popularity of the original. This may imply that Billy Joel has exceptional ability in making lists into songs.
A skill akin to making the shiniest mud ball
 
I am trying to upload an exe files and some scripts to a SQL db qith SQLAlchemy. This is my first time uploading script files, previously image uploads worked fine with b64encode. But today, b64encode does not work for such files, I get an error Data too long for column 'fixlet_file' at row 1 from the MySQL engine in SQLAlchemy. Each files is just around 50KB, so not sure what's wrong. Besides, is it a good idea to store the entire b64encoded file string in the database?
 
1:01 PM
Not sure I see the benefit of base 64 encoding the data before storing it.
 
i couldn't find any other way to store it using Flask.
 
BLOBs are one way to store arbitrary bytes. Shouldn't require any conversion to base64-encoded string, or anything
What type is the fixlet_file column, currently?
 
I mean my fixlet_file data type is LargeBinary which translates to a blob in SQL. But when I send the file as it, I get a different error.
 
Ok, that seems worth investigating. What error is it?
 
'bytes' object cannot be interpreted as an integer
i've been investigating for 2 hours now
what a Monday!
 
1:07 PM
Interesting.
Ok, time for me to actually go read the SQLAlchemy docs and see if reality matches my expectations
 
I have been reading the docs for a day, but I'm sure I'm missing something or making a silly mistake
According to the BLOBs Wiki article, BLOBs are typically images, audio or other multimedia objects, which is the reason why image uploads work without b64encoding.
 
Ok, I've verified that SQLAlchemy has no problem inserting bytes into a LarbeBinary column, no b64 required. So it seems likely to me the problem is somewhere between "user uploads file" and "SQLAlchemy is asked to insert data"
From the error message, it seems like something is trying to convert the bytes to an integer. You should consult the stack trace to determine where this is occurring.
 
yes, this works for jpg, png files but my files are exe, ps, py scripts. I just did a fixlet_file.read() and I get the same error: Data too long for column 'fixlet_file' at row 1..and I see that it tries to store a byte string for fixlet_file:b'MZ\x90\x00\x03\x00\x00... which is too long for storage. The file itself is just 50KB.
 
1:23 PM
cbg \o
 
Strange, it works just fine for me when I try it on py and exe files.
 
ok, I'll try a py script. I have only tried exe till now, my bad.
 
@roganjosh it seems like OP did want to embed his Flask app in his existing "HTML site" at least we got some closure. (in reference to chat.stackoverflow.com/transcript/6?m=43250475#43250475 )
 
The exe was 1598 KB, for what it's worth
 
you know what, the py script uploaded succesfully.
could it be the exe then. I was trying to upload the Firefox setup file as an example, about 304KB in size
 
1:34 PM
Once you have the data in a bytes object, SQLAlchemy should have no idea whether the data came from an image or a py file or an exe. As far as it's concerned, it's all just meaningless ones and zeroes
 
i read that the right way to do this is: the file itself should not be stored on the database, rather an image url of the file only. I don't see any tutorials that talk about this.I am new to this.
 
That seems like a contradiction. You say that you can't find a tutorial that mentions that, but you also say that you read something (a tutorial?) that says that.
Hmm it occurs to me that all my "it works on my machine" talk is kind of unfounded because I didn't actually start a session and commit the data, so there's really no telling whether it could actually construct a valid insert query for the row I created. And my SqlAlchemy is so rusty, I can't remember how to actually do that. I just keep getting "no such table" when I try.
Oh, I missed the create_all call. Yep, that'd do it.
 
1:58 PM
Hello guys, I am using Pycharm to learn Python. Whenever I open a new project or start Pycharm, it will start indexing and updating all the libs. I have searched in the settings option but couldn't find how to stop this automatic indexing. Can anyone help me with this please?
 
I would be surprise to learn that PyCharm doesn't have a way to disable the this feature.
 
Result:
Reading file C:\Program Files (x86)\Mozilla Firefox\firefox.exe.
About to commit 454.608 KB of data.
Data committed.
So SQLAlchemy can definitely store 400+ KB of executable file data in a BLOB column.
 
@MooingRawr Yes, I think i'll need to search more about this.
 
Back to the topic of "the file itself should not be stored on the database", I think it's a valid design approach do do either:
1) store binary data on the file system, and only store the path to it in the database
2) store binary data directly in the database
1 is attractive if you think you're going to need to manipulate the data with, for example, image editing software. 2 is attractive if your production environment has tight security requirements, and your processes can only manipulate your database file, not add arbitrary new files within your project directory.
 
sorry I don't use PyCharm, so I wouldn't know. maybe someone who does will help out later today
 
2:05 PM
I read that in a blog but he didn't teach how to store an image url. He goes like: It is recommended to store image url's in the database but for those of you who want to store files in the db....should do this..
 
I assume by "image url" he means "the absolute path where your image resides on your hard drive"
Unless he means "the URL where the image is currently hosted online", which seems insane since you can't trust any webpage to be reliably accessible at any point in the future
 
I'd go with the first explanation
 
Extra double insane would be "the absolute path of the image on the user's hard drive", which is useless since your server can't access my computer's files
Storing the path is easy. You make a filename column, with type String, and give it values like "C:/users/Kevin/my_image.png"
 
Is it safer to store in a db? I think so it is. I'm designing an API that fetches these scripts from the db. When I store the script file and query in the MySQL command line, it actually stores the entire code in the scripts in the fixlet_file column. Whoa!
ok, if I am storing the absolute path, I have control over this path as I have admin access and I can make this a static UPLOAD_FOLDER path. So, I should change the fixlet_file data type from LargeBinary to String, I'm assuming.
 
It's safer in the sense that there's no chance of a discrepancy where the row says "my_image.png" exists, but the file got deleted from your project's directory. With approach 2, if the row is there, the data is there.
 
2:16 PM
cbg
 
2:27 PM
"Well I'll just not delete any files then, problem solved", you think. But what if you want to move your project from c:/users/kevin/projects to c:/programming/python/projects? All of your rows will still refer to C:/users/kevin/projects/my_image.png and similar, but that's not where they are any more. Storing 100% of your data in the db makes it more portable.
"Ok, I'll just store the relative paths of the files, with respect to the root directory of the project", you think. "Moving the project won't break those paths." Hmm, that's not a bad idea.
 
cbg Moxie
 
It's ok if the file is stored in the db. But what I don't like is that it stores the entire script contents(code) into the column. I just did fixlet_file.read() which essentially just reads the whole file contents.
 
recbg
 
I don't think I see the distinction between "the file is stored in the db" and "it stores the entire script contents". How would you store the file without storing its contents?
 
exactly.
 
2:33 PM
So you agree with me that it's fine?
 
its not in prod yet and its too early, and we will have a meeting about this..It all depends how the client wants it, whether I like it or not
another strange thing is, I cannot upload normal files about 70KB or so either. I just tried a pdf and it didn't upload. But when I tried an exe about 37KB and it worked..Is it m code? I'm going nuts!
 
If you can manage to create an MCVE that doesn't require django, I'd be quite interested in seeing it
 
The same Data too long for column 'fixlet_file' at row 1 all day!
 
DSM
I'm reluctant to get involved this late in the process, but do we know the length associated with the fixlet_file column?
 
Well, I think I'll should do that. A simple db with a file upload function in SQLAlchemy in a separate file..away from the mess I've created for myself.
@DSM
the fixlet_file column is defined as LargeBinary in SQLAlchemy which translates to a BLOB in MySQL behind the scenes. A BLOB can take upto 2,147,483,647 bytes.
 
DSM
2:44 PM
Well, a LARGEBLOB can (or 4 GB, can't remember if it's 4 or 2.). Are you sure you're not using BLOB?
I mention this only because the standard BLOB maximum size is 64KB, which would match your problems setting in at about 70KB.
 
Hi everybody, thanks in advance for our help and comprehension, I try to make a list comprehension, than a loop in the code the code is following , work :

for i in b:
if u'nan' in i:
i.remove(u'nan')
c += [i]
else:
c += [i]

its remove some u'nan' string
if I make it in a list comprehension, the remove make the list immutable and give None instead the cleaned list :

c = [i.remove(u'nan') if u'nan' in i else i for i in b]

[[ some string] , None , None ... , [other list with string], None, None ...]
 
That explains it..I looked at a different link to get that number. I should check the official MySQL docs..I am sure its a BLOB as I checked MySQL.
 
@YoanBouzin List comprehensions take the return value of your expression and put it into the resulting list. remove returns None, so your resulting list has Nones in it.
 
DSM
Oof, it's LONGBLOB, not LARGEBLOB. That's what happens when you're going from memory. Well, I do numerics, not databases. ~
 
2:50 PM
The quick and dirty solution would be to modify the expression so that it returns i irrespective of which branch evaluates in the ternary expression. Something like c = [i.remove(u'nan') or i if u'nan' in i else i for i in b]
 
@Kevin they're a possibility to have the same behavior than my loop ? the loop give me empty list or remove correctectly the targeted string, in the list comprehension, if the targeted string is found, whatever what are the list, its return None, so I was expected the same behavior ^^"
 
But it's generally frowned upon to use mutating methods inside a list comprehension, so the Pythonic solution probably wouldn't involve .remove at all
 
aah thanks you repply more faster than me ;)
 
Maybe something like c = [[x for x in i if x != u"nan"] for i in b]
 
@Kevin thanks ! now its work !
both are also given the same result as expected
 
3:09 PM
@MooingRawr thanks for letting me know. I think the OP will have a lot less pain just building it out in Flask
 
3:22 PM
"This orb, which is a unique item that appears only once in the game, lets you reassign your skill points", and "these scrolls, which can be used only once, increase the power of your current weapon" make me think this game's designer is intentionally encouraging my mindset of "better wait until later to use this... Oops, I'm at the end of the game and I never used them"
I would attribute it to a quick production cycle but they had time to commission translations for thirty languages so I don't think another 24 hours of playtesting would have extended the critical path any
 
Why do so many newbies put time.sleep calls in their input dialogues, eg here? My theory is that they learned to program from a tutorial that creates a text-based adventure game over the course of the lessons. The game has delays in its input dialogs, so they think that you're always supposed to do that.
 
I attribute it to a flair for the dramatic. If the computer waits a second before replying, it makes it seem like it's "thinking"
 
sP_
@AndrejKesely I'm not curious what the question was :P
 
Same reason that some newbie scripts have a "typewriter" style that displays each character one at a time
 
@sP_ The question was about how to replace Python's and and or with && and ||. And why Python's and and or are bad :D
 
3:33 PM
Create a typewriter-effect animation for strings in Python explicitly admits that they're mimicking depictions of computers from movies and video games
I like War Games as much as the next guy, but UI design has progressed since then
 
rb
 
does anyone familiar w/ Django know of a way to create a form field that is filled with audio recorded directly from the microphone?
 
@Kevin Fair enough. And I guess that's why text-based adventure games do it.
 
i've been trying to figure this out for days screwing around with a bunch of different javascript and javascript libraries
and i just can't find anything reasonable
 
@Aran-Fey nvm my comment, i forgot that it's possible to except specific exceptions. As long as it can be somewhat ascertained whether the exception was thrown during enter or the with-block i'd be fine with the construct.
 
3:42 PM
@AmagicalFishy That sort of thing is a bit painful because audio handling is OS-dependent. It's hard enough to do portably in Python. But I have no idea how you'd do it client-side with JavaScript. For security reasons it hard to read local files from JS, so I don't imagine reading audio streams would be any easier.
 
Is there a reason why numpy makes my life difficult?
>>> np.array(b'\0\0\0', dtype=np.uint8)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: b'\x00\x00\x00'
>>> np.array(list(b'\0\0\0'), dtype=np.uint8)
array([0, 0, 0], dtype=uint8)
 
DSM
Is there a reason you aren't using frombuffer?
 
@PM2Ring ugh this is turning out to be so difficult. i've managed to convert the recording to a float32array (for .wav) and am trying to send it to the server via ajax
but for some reason request.POST.getlist('channeldata[]') is just returning an empty list
 
@DSM Because I didn't know it exists!
 
sP_
@AndrejKesely Thanks! I meant to type 'now', but for some reason my hands decided to type 'not'.
 
3:56 PM
@AmagicalFishy Sorry, I don't know Ajax. But WAV file samples are normally signed integers, not floats. That's what I've always used.
 
4:15 PM
@PM2Ring ah, yeah. in python they're signed integers (i'm not sure why, actually). in a lot of other applications, they're floats between -1 and 1 (so i've also got to convert the floats to an appropriate integer!)
 
Hello
import math


def solution(A):
    decimal = getDecimalFromBits(A)
    A = getBitsFromDecimal(-decimal)
    return A


def getBitsFromDecimal(number):
    number = -number
    result = []
    while number != 0:
        result.append(number % 2)
        number /=  -2

    return result


def getDecimalFromBits(A):
    result = 0;

    for index, bit in enumerate(A):
        # You can either use math.pow or ** the exponentiation operator
        # Be careful to cover odd indices when using ** operator
i got this error Traceback (most recent call last):
  File "exec.py", line 141, in <module>
    main()
  File "exec.py", line 82, in main
    sol = __import__('solution')
  File "/tmp/solution.py", line 36
    print "Number: %s -> Bits %s  -%s A: %s" % (number, A, number, neg)
                                           ^
SyntaxError: invalid syntax
RUNTIME ERROR  (tested program terminated with exit code 1)
 
print without parentheses is only legal in Python 2
You want print("Number: %s -> Bits %s -%s A: %s" % (number, A, number, neg))
 
oh
yes i'm using python 3
how can i change it?
 
As in, "how do I use Python 2 instead of Python 3"? You can install it, and either directly run the python executable in the Python 2 directory, or do py -2 your_script_name_goes_here.py
 
a no
i changed
 
4:22 PM
Seems like a lot of work, though. It would be better to just change the print statement to use parentheses, like in my above message
 
Example test:    [1, 0, 1]
Output (stderr):
Invalid result type, int expected, <class 'float'> found.
RUNTIME ERROR  (tested program terminated with exit code 1)

Example test:    [1, 1, 1]
Output (stderr):
Invalid result type, int expected, <class 'float'> found.
RUNTIME ERROR  (tested program terminated with exit code 1)

Detected some errors.
i got this error
i have wrong logic i think so
 
Quite possibly. When I run your code, it certainly prints a lot of floats.
 
yea
print a lot floats
and i need to print array
array of integer
 
Welp, turns out the bug I've been hunting for hours is actually coming from a module I depend on. Time to write a bug report and twiddle my thumbs...
 
For example, given A = [1,0,1] (X = 5), the function should return [0,1,0,1,1] (X + 1 = 6). Given A = [1,1,1] (X = 3), the function should return [0,0,1] (X + 1 = 4).
 
4:27 PM
The first thing you should examine is getBitsFromDecimal. It is probably useful to note that 5/2 gives different results in Python 2 and 3. In Python 2, 5/2 is 2. In Python 3, 5/2 is 2.5.
 
4:43 PM
For bit-level tasks like these, the shift operators, >> and << may come in handy
 
DSM
@Aran-Fey: don't wait for happiness. Fix the upstream bug and monkeypatch.
 
I'm in no rush to get that fixed. I planned ahead and made my code work with... uh... 8 different backends. One of them not working doesn't hurt me much :)
 
wim
>>> datetime.datetime.strptime('', '')
datetime.datetime(1900, 1, 1, 0, 0)
what the...??
 
clearly it should be datetime.datetime(1970, 1, 1, 0, 0) instead
 
Makes sense to me. If strptime("23:42", "%H:%M") gives datetime(1900, 1, 1, 23, 42), and strptime("23", "%H") gives datetime(1900, 1, 1, 23, 0), then by induction I would assume strptime("", "") to give datetime(1900, 1, 1, 0, 0)
I wouldn't cry many tears if the devs added a ValueError: don't provide an empty format string, are you crazy? check, but I also don't mind it as-is
I would go check the C standard to see if strftime is required to work this way on an empty string, but I forget how to find it without sending 80 dollars to the ISO-9001 committe, or whoever it is that owns it nowadays
 
5:00 PM
@EduardoHerrera what about that wall of text?
 
@EduardoHerrera How coincidental, that we were just talking about strptime, and strptime is exactly what would be useful for parsing those time values.
 
okay
@AndrasDeak i just want to do this homework
 
okay, but we don't :P
 
@AmagicalFishy Are you sure? I've never seen a WAV file that uses floats for the samples, only ints. I've only worked with 16 bit WAV myself, but it also supports 8 bit. The Wikipedia article is annoyingly vague in that it doesn't say that the samples must be integers, but this page makes it pretty clear.
Of course, most sound generation & processing programs will generally work with floats, so you need float <-> int conversion functions. But in ancient times, when many CPUs didn't have float instructions it was quite common to do audio generation & processing with integer arithmetic since it was faster than calling floating-point library code.
 
hahaha i know
 
you can still ask for help with your homework, but link it in a code paste service or something instead of cluttering up chat with noise
 
@Kevin I have The Standard C Library by P. J. Plauger. It's a bit ancient: it was written just before ANSI C metamorphosed to ISO C, so some of the info in it has been superseded, but it's still a pretty good reference. I'll see what it says about strptime / strftime.
 
That seems like something they wouldn't meddle with between versions
 
5:13 PM
kevin'ed
 
@EduardoHerrera welcome, please read our room rules
 
ok
Invalid result type, int expected, <class 'float'> found.
how can i turn to integer?
 
google it
 
Stubbed my toe really hard last week and I still get a little twinge now and again... I wonder if it's possible to break your foot just a little.
 
yup
you can splinter a bit of bone for instance
 
5:28 PM
I'm mad at my doctor because he forgot to send me the results of my last blood test so I might just go without medical care for the rest of my life out of spite
 
if it's any consolation, broken toes are usually left alone as far as I know (except big toes of course)
 
@AndrasDeak hello
 
A bit hard to put a cast around each individual digit, I expect
Luckily thanks to a preexisting quirk of my gait, I put basically zero weight upon the ones in question while walking regularly
 
clearly you aren't a duck
 
I am many things, and nothing
 
5:34 PM
@Kevin Agreed. The book is from 1992. The preface begins "This book shows you how to use all the library functions mandated by the ANSI and ISO Standards for the programming language C. [...] The book also shows you how to implement the library. I present about 9,000 lines of tested, working code." IOW, it contains a complete implementation of the standard C library, including test code.
The definition of strftime (and strptime) say nothing about what dates & times are valid, that's covered by the definition of struct tm. And the Standard says that the tm_year field is an int of the years since 1900. In the preamble to the <time.h> chapter Plauger writes:
«The C Standard contains enough weasel words to let nearly everybody off the hook. A system need only provide its "best approximation" to the current time and data, or to processor time consumed, to conform to the C Standard. A vendor could argue that 1 January 1980 is always the best approximation to any time and date. A customer can rightly quarrel about the low quality of such an approximation, but not whether it satisfies the C Standard.»
 
datetime: strptime('', '') == datetime(1900, 1, 1, 0, 0)
wim: Uh, that's ridiculous.
datetime: I have a permit. [hands him the C standard]
wim: This just says, "I can do what I want"
A complete implementation of the C library, but if you want to use it, you have to retype it out by hand. ♫ It's like rain on your wedding day ♫
 
A struct tm that's cleared to zero isn't a real data, since the tm_mday field should be the day of the month from [1, 31], but zeros in all the other fields are valid. And if you set tm_mday to 1 and leave all the other fields at 0, then it is the correct data for 1 January 1900. Even the tm_wday field (days since Sunday [0, 6]) is correct.
 
It's gonna be trouble when we switch to holding leap day on Feb 0th
 
5:49 PM
@Kevin :) The code is in a nice clean monotype font (Courier bold), so it should scan easily, and he gives you explicit permission to do so, but not to sell copies of it. But you can freely use his code in your own work, providing you include his copyright notice. And he tells you where you can purchase the code in machine-readable form., but I guess that info might be out of date. ;)
 
That location was torn down decades ago and turned into a Taco Bell. But if you go in and order an 0xDeadBeef, they'll reach under the counter and hand you an unmarked 5¼-inch floppy, once white but now turned beige from age and exposure to ambient hot sauce droplets
To this day, if you stand by the tortilla station at the stroke of Fourthmeal, you can still hear the faint voice of Old Man Plaguer in the distance
(Taco Bell of course being a subsidiary of Bell Labs, and consequently having some peculiar contractual obligations)
 
6:05 PM
Oddly, I can't find the source on Plauger's web site, free or for sale. But it looks like it's not hard to find PDF copies of the book, and it's available in Kindle format. Even though it's been superseded by a couple of new generations of C it's still a great book. And Plauger knows what he's talking about, since he was the chairman of the library sub-committee of the ANSI committee that developed the C standard.
Sorry, he was the chairman of the Library sub-committee.
 
DSM
I enjoy the idea of "Taco Bell Labs" more than I should probably admit.
 
Yeah it's pretty much the high water mark for my creative output this week
I may as well take Tuesday through Friday off, now
 
6:31 PM
Of course, the code wasn't really intended be used as the library code for a C compiler, although it can be. It's a reference implementation that's designed to be clear and easy to read. The code is efficient, but it uses no "clever" obscure optimizations. Every function is explained in the main text, but if you need to know exactly what any function is supposed to do you can just read its source code.
 
Reminds me of the code samples in the itertools documentation.
"This isn't how it's implemented, but you can pretend it is, if reading C isn't your idea of a fun time"
 
in python2, can we pass 0 as an optional integer type argument to argparse? It seems to only recognize integers > 0
 
7:07 PM
I wish python would mimic the run a function through a string like Unity does, maybe I'll just make one, it isn't complicated.
 
okay
 
That could allow some kind of switch like implementation in python
 
if you want substantial responses you'll have to elaborate on "run a function through a string like Unity does"
 
hey guys?
If a segfault is happening w/ a pybind11 .so, how can I use gdb to run the core dump in this context?
 
hey?
 
7:11 PM
\o
 
@OneRaynyDay locks doors, closes windows and hides under the table :p
 
@Simon sorry for sp00k
 
Cabbage OneRaynyDay, I'm totally confused by what you mean , laurel
 
@AndrasDeak My interpretation of that is: "I wish Python had an invoke function, so I could do s = "foo"; invoke(s) #calls foo()"
 
I guess we'll never know
 
DSM
7:16 PM
Too bad that's completely impossible. (looks around meaningfully) Completely. Impossible.
 
"Then you set up a switch, like f = "foo" if expr else "bar"; invoke(f)"
But of course, you can already do that without invoke or similar, because functions are first class objects.
 
I'm sure there's a legitimate self-harming reason somewhere
 
I don't know, it just drives me nuts not seeing a switch implemented in python
 
Why?
 
>>> def f(x): return x * 2
...
>>> def g(x): return x + 10
...
>>> d = {0:f, 1:g}
>>> d[0](23)
46
>>> d[1](23)
33
 
7:19 PM
use a dispatch dict ^
 
Tadaa, dispatch dict
 
DSM
Behold, a dispatch dict!
 
Lo!
 
damn never heard of that
the more you know I guess...
 
And if your cases are consecutive integers starting at 0 (or some low integer), then you don't even need a dict, you can use a list or tuple.
 
7:22 PM
The broad lesson is: functions are objects, so they can be used anywhere that an object can be used. You can assign them to variables, you can append them to lists, you can use them as values in dictionaries, you can return them from other functions. etc etc
 
x = 0; (f, g)[x](23)
 
That's a good thing to note, thanks. I might end up using this in more projects.
 
but these are usually dicts, and so you don't have to end up with integer keys to begin with
instead of "hmm, which was the index of the frobnicator again?" you can just go "disp['frobnicator']"
 
A dispatch dict / tuple can be handy, but bear in mind that a simple if...elif...else may be more readable, and in some cases more efficient.
x = 23
if case == 0:
    v = x * 2
elif case == 1:
    v = x + 10
#etc
 
yea, but if you have like 10+ cases, it might be nice to put in there. If there are 100+ just let the machine learn screw up miserably to learn....
 
7:28 PM
That's more efficient than Kevin's example because it avoids the overhead of an extra Python function call. And Python function calls are relatively slow, compared to calls to built-in functions that are written in C.
If you have a 100 cases, then the dispatch dict is probably better, because dict lookup is O(1), whereas processing all the tests in a huge if...elif... chain is O(n) because it's a linear scan until it finds the matching condition.
 
7:42 PM
Yesterday I watched Zero Hour! and I spent the whole time wondering if the pilot was the inspiration for the visual design of Launchpad McQuack from DuckTales and I don't know anyone in the world that knows enough about 1950s disaster movies and late '80s cartoons to confirm whether I'm just imagining things, and this bothers me very much
I think it's the butt chin, mostly
 
Guys, can anyone help me on this, this is kind of an array in my program. If my output is 'Platinum' and 'Tier 1' then it's suppose to give value = 'critical' and similarly for other boxes. I have been using if elif statements but that is amounting to lot of lines and I feel it should have a shorter and smarter way. Also, it must be case insensitive, that is, it could be Gold, GOLD or Gold
Platinum Gold Silver Bronze
Tier 1 Critical High Medium Low
Tier 2 High High Medium Low
            Platinum	Gold	          Silver	Bronze
Tier 1	Critical	High	        Medium	Low
Tier 2	High	        High	        Medium	Low
Tier 3	Medium	Medium	Low	        Low
Not able to get the table formatted correctly. X_X
 
What exactly are we looking at? A dataframe?
 
Paste the code
 
sure.
but it is just an if elif statement.
 
Also there is also CodeReview which is made for this
 
7:50 PM
@property
def riskfactor(self):
if device.cmdbquery == 1 and 'Bronze' in device.grdbquerymetallic:
return 'Low'
elif device.cmdbquery == 1 and 'Silver' in device.grdbquerymetallic:
return 'Medium'
elif device.cmdbquery == 1 and 'Gold' in device.grdbquerymetallic:
return 'High'
elif device.cmdbquery == 1 and 'Platinum' in device.grdbquerymetallic:
return 'Critical'
elif device.cmdbquery == 2 and 'Bronze' in device.grdbquerymetallic:
return 'Low'
elif device.cmdbquery == 2 and 'Silver' in device.grdbquerymetallic:
This was working fine, until i encountered text like 'GOLD'
 
d = {('platinum', 'tier 1'): 'Critical', ('platinum', 'tier 2'): 'High', ('platinum', 'tier 3'): 'Medium', ('gold', 'tier 1'): 'High', ('gold', 'tier 2'): 'High', ('gold', 'tier 3'): 'Medium', ('silver', 'tier 1'): 'Medium', ('silver', 'tier 2'): 'Medium', ('silver', 'tier 3'): 'Low'}
x = "GOLD"
y = "tier 1"
print(d[x.lower(), y.lower()])
 
@KaranM Yes, there's an easier way to do that than a whole bunch of if...elif. Coincidentally, we were just talking about this kind of thing a little while ago. Ah, it looks like I've been Kevin'd. :) But I'd probably do it a little differently.
 
I bet there's some incredibly cunning way to load this into a dataframe or something
 
@Kevin Kevin, i believe this wont work if the output from my sql query is read as GOLD and gold differently into this?
 
Slightly tricky since the "tier <whatever>" indices have spaces in them but I've learned not to underestimate pandas
 
7:54 PM
You could use a dictionary or check the number first then check the string. That or since your conditions are iterable, you could use a for loop and store the strings in a list or something of the sorts.... I don't think the time complexity of the for loop would look great, but it does shorten the lines.
 
@KaranM Go ahead and try replacing x = "GOLD" with x = "gold" and see if it works or not.
 
Does anyone happen to know a video hosting website for really really short but looped videos? I was planning on using imgur, but their API won't let me upload mp4 videos :/
 
isn't that what vine is for?
 
Also for the Case insenitivity, you can just simply lowercase it automatically
 
vine was shut down though
 
7:55 PM
@Kevin I have got a bunch of output from sql queries and for some iterations it has a 'Gold' in it and for some others it has 'GOLD'
 
Youtube...
 
ah, I don't keep up to date with all these new-fangled thingamajigs
 
Alright, well, I'm sure you'll figure it out.
 
@KaranM we understand that. We're suggesting you use .lower() to get them both to a common denominator for checking the dictionary
 
@KaranM, that's why you lowercase it automatically
 
7:56 PM
@NiNisanNijackle Youtube doesn't loop the video. My videos are literally less than 2 seconds long. Looping is a must
 
Just like my code is already doing
 
@NiNisanNijackle Oh okay! got it. will try to do this
 
@Aran-Fey that sounds weird by the way because I'm pretty sure I've heard people complain that even gifs are automatically converted to videos on imgur
 
Yeah, that's true. The problem is that the quality is garbage if I upload gifs. They let you upload mp4 videos, but only from the desktop website.
 
oh, I see, emphasis on API
 
7:58 PM
I have 2500 videos to upload :^)
 
01:00 - 20:0020:00 - 22:00

« first day (2830 days earlier)      last day (2115 days later) »