« first day (3948 days earlier)      last day (993 days later) » 

12:21 AM
@AndrasDeak btw, Managed to make this work by using b in front of ''.join :D
 
 
3 hours later…
3:43 AM
cbg all
 
 
1 hour later…
user16280768
5:01 AM
Hai is there any way to run code without Cuda in PyTorch ...... AssertionError:
Found no NVIDIA driver on your system
 
5:21 AM
might be a trivial question, but have you installed those?
ok I read that wrong, my bad
 
user16280768
5:59 AM
@python_user any solution for that one ??
 
6:37 AM
@Harry unfortunately I dont know any thing about these ML AI libraries
 
7:23 AM
Do I understand it correct? Strings that are passed as a parameter can't be changed by a function.
 
strings are immutable, yes,
the function can ofcourse make new local strings from that parameter, but that will just be making new local string objects
 
and a=1 ... some code ... a=2 does not behave the same way as in C++ for example?
 
i dont know how C++ behaves
when using* python, it's important to learn whatever python does
for how python variables work, i recommend this resource.
 
7:34 AM
Mmh, so this function really should have a return value?
def replace_asterix_with_letter(guessed_letter, word_to_guess, word_asterix):
    if guessed_letter in word_to_guess:
        for i, x in enumerate(word_to_guess):
            if x is guessed_letter:
                word_asterix[i] = guessed_letter
because otherwise it changes nothing
also it's quite wrong i see now
because strings are not changable
 
@ParitoshSingh Thanks, that looks like a really nice thing to read
 
@SAJW if x is guessed_letter is also incorrect. Use ==.
 
ah, right!
 
7:53 AM
@SAJW FYI '*' is called an asterisk. Asterix is a cartoon character.
 
Maybe the next function uses Obelix, who knows
 
mostly I use the term "star" even though I am aware of asterisk
 
to be frankly I wanted to use underscores but I need to find a font which makes it look like _ _ _, but a little closer
because ___ is ugly to guess how many letters that can be :D
 
Or random emojis
 
also I think at the end I need to use images, to have a letter above an underscore if guessed correctly
 
8:10 AM
@SAJW add spaces for printing?
And some terminals support underlining stackoverflow.com/questions/55065640/…
 
8:40 AM
It's always a gamble whether unicode characters look the same in every font, but you can consider using FULLWIDTH LOW LINE characters:
>>> print('\N{FULLWIDTH LOW LINE}'*5)
_____
ah well. That's not how it looks like in my terminal. Thanks for proving my point, SO
 
hello
 
hello
 
Do you know little bit of javascript?
 
there is a JS room you can ask your questions there
 
Seems like nobody uses chat on SO nowadays
 
8:43 AM
you are free to ask any python related questions as long as they are within rules
 
all rooms are quite
 
its a weekend where I am, and friday eve (somewhere else probably), so traffic could be less
but JS room must be pretty active compared to the C / C++ ones
 
is this possible in python? def func1: some code func2() def func2: some code func1()
 
try it
 
9:22 AM
ok, I give up trying to learn tkinter when I'm not even fluid in python itself. Reading a tutorial now from python :)
 
9:39 AM
@SAJW good call
 
10:07 AM
what is meant with data in "model" in MVC? like files on a computer or rather computations?
 
@SAJW did you get sidetracked? That's not python tutorial material.
Just making sure you're not reading a django tutorial or something
 
I want to seperate the logic, whatever that might be, from the representation (even if it's just a simple program for the commandline)
 
if you are just starting out, I would recommend, you make things work
 
so I stumbled upon MVC...
 
then focus on design
 
10:12 AM
@SAJW in your case that just means having a print_state function that uses the game state
And not adding underscores to your data for empty words
For instance, only store found letters, and the printing figures out where underscores go
Or store the found indices alone. Things like that.
Named patterns are overrated
4
 
Meanwhile I'm trying to figure out what on earth a Controller is supposed to be
 
some_string='lol'
some_string='berta'
print(some_string)
seems to work as I expected it
output: berta
 
MVVM is the only pattern that helped me, back when I was making Android apps
 
can you force a parameters type of a function?
 
nope
 
10:27 AM
@Aran-Fey If this was Flask, you could probably think that the functions you associate with different URL paths would be the controller, though I don't think that fits the strict definition
 
so the views in flask are the views (V) in MVC? just to clarify
 
The View is the template itself that the user interacts with
 
Hmmm. I'd probably consider that part of the UI (i.e. the View) I think
 
13 hours ago, by Andras Deak
I was talking about C++, to be clear. Python's compiler or any other part has no issue with names shadowing one another.
 
But it's the route that orchestrates what actually happens. The view is the template that the user interacts with and submits a request. The app.route associated with that form URL, say, can then decide how it wants to process that request e.g. determining a code path based on whether it was a GET or POST request, so that makes it the controller, and the models would be things like SQLA models for your database
But Flask wasn't designed strictly to this paradigm. I think it would be more obvious in something like Java but I've never designed a website in Java, only API endpoints
 
10:34 AM
Imagine that you're writing a tkinter GUI instead of a website with flask. When you press a button, instead of taking you to a different URL, it just brings up a new dialog or whatever. Does that mean the button's event handler is part of the Controller?
 
I would guess so?
Can the event handler take state from the application and provide different outcomes from the button press?
 
If the answer is no then I still don't know what a controller is, and if it's yes, then I don't understand why View and Controller are 2 separate things despite being so strongly connected that they're inseparable
@roganjosh I guess it could
 
The Flask example is easier for me to separate because I can clearly define a backend action of a URL route. But then I'd be in the same quandary as you if I also have pure JS event handlers embedded in the template. I don't know what they are.
 
Judging by the fact that there's like half a dozen variations of this pattern (MVC, MVVM, MVB, ...), it seems like this is quite clearly the least crucial part of the design pattern
 
28 mins ago, by Andras Deak
Named patterns are overrated
 
10:42 AM
Agreed
 
Yeah. I think it's relatively easy to understand what's idiomatic with each framework and that's probably all that matters
 
@Aran-Fey fwiw, i believe the answer to this is yes.
but yeah, trying to makes apples and oranges out of interconnected things should only be taken so far.
 
 
2 hours later…
12:54 PM
is the only cross platform way to "clear" the screen by printing 50 newlines?
in the cmd
 
print("\033c")
that clears screen in my terminal
 
?c gives it for me (windows)
 
cross platform simply means if else :P
 
are all Linux OS one OS for python?
but yeah apart from that, and superfluous code, I got it to work
just one round tho hehe
(i know that's easy to change)
 
That doesn't really have anything to do with the OS... it's more about the shell and the terminal
 
1:07 PM
pastebin.com/K116DVWq do I make unnecessary work here by always converting string to list and back?
in the big while loop
 
yes, use the list for storage and only convert it to a string when you want to print it
 
also to be able to manipulate it
 
Also, asterisk_word should really be underscore_word?
 
oops XD
of course!
oh I see it now
I can print lists without making them to strings
 
1:42 PM
I guess that is not what Aran Fey meant
 
tbh even the list is pretty unnecessary. Rather than looping over the word to find out which underscores you have to replace with letters, you might as well just generate the whole thing based on word_to_guess and guessed_letters
 
how does the statement then look like for determining whether the game is won?
in pseudocode
I removed the strings/list conversions now entirely and work with lists
 
every letter in word_to_guess exists in guessed_letters
 
2:21 PM
like this then?
def underscored_word(word, letters)
	some code
	return underscored

underscored_word=newstring(word_to_guess, guessed_letters)
(assuming there is no function already just for that)
 
pretty much
 
mmh what do search in google? I tried: generate strings with rule python. or is the rule basicly an if else statement?
 
2:46 PM
@Aran-Fey I can't think of a way to do this without one loop, if you do, please enlighten me.
can be in pseudo code of course
 
Naturally you do need a loop
 
2:58 PM
@SAJW by the way, don't forget to filter out non-ascii-letter words. Like vis-à-vis.
 
I do wonder how some people keep their high horse going some times. I wrote "Why are you using Python 2.6? That's now 13 years old and completely unsupported" and I get pulled by another question viewer suggesting that rather than "lambasting" the OP, I should solve their non-MCVE. Not that they contributed anything else themselves in reprimanding me. How overly-dramatic can people get?
 
Let me get my fainting couch
 
@roganjosh drama is the spice of life. ;)
 
A fainting couch sounds like a good idea!
 
3:23 PM
mmh is this bad?
def string_underscored(word, letters):
    underscored=''
    for l in word:
        if l in letters:
            underscored+=l
        else:
            underscored+='_'
    return underscored

...
#somewhere later:

underscore_word=string_underscored(word_to_guess, guessed_letters)
ah obviously I could scrap that altogether
print(string_underscored(bla,blub))
 
Building strings sequentially like that is not a good idea
That's why we have str.join(). I assume this is related to your previous code post but, without knowing how you intend to fit this function into that code, I'm going to say that you're probably moving in the wrong direction
 
this was the only solution that I could find that doesn't involve converting strings to lists
 
So convert it to a list. Are you maybe overthinking this?
 
"tbh even the list is pretty unnecessary" I took that serious hehe
 
Umm. You do need a list, but you don't need to convert a string to a list
 
3:29 PM
This isn't a performance-critical bit of code (unless you're running the Hangman World Championships. That's - I assume - a big deal). Just get something working and build some more familiarity with the language
 
@SAJW That particular list is unnecessary. The one with letters and underscores in it. There's nothing wrong with lists in general
 
3:52 PM
is appending to a list better than adding elements to a string?
*adding letters to a string
 
yes, because strings are immutable, so python has to create a copy of it
 
(leaving implementation optimizations aside)
 
mmh, ok, then this should be better than the previous:
def string_underscored(word, letters):
    underscored=[]
    w=list(word)
    l=list(letters)
    for x in word:
        if x in l:
            underscored.append(x)
        else:
            underscored.append('_')
    string_underscored=''.join(str(x) for x in underscored)
    return string_underscored
 
Why are you converting word and letters to lists?
 
Oh right I could use string[i]
 
3:58 PM
Yes. A string is a sequence so you can iterate through it just as you would a list
 
python can iterate through strings, so you literally don't need to index the strings or anything, the code as is works
 
Depending on how big letters was, l=list(letters) might make sense as l = set(letters) but, given you're confined to the alphabet, it probably won't make a huge amount of difference here. I don't know how Chinese characters are represented, though, so it might matter more if that's the case :P
I've been meaning to understand how Chinese keyboards work, actually. That's a big point of ignorance on my part because I can't visualise how you can make a meaningful keyboard from my current understanding of how the language works. I'll dig up a video later
 
Just do for letter in word:
 
@roganjosh I think they use syllables like for pokemon first gen, so instead of printing words the print el, et, tac, or whatever syllables they have
(my assumption)
 
4:07 PM
They also have 4 (IIRC) intonations for every word. Things get complicated fast
 
 
7 hours later…
11:19 PM
@SAJW What Aran-Fey said at 2:05. Similarly, you can do the in test directly on the letters string.
Also, in string_underscored=''.join(str(x) for x in underscored) the str(x) call is pointless, since x is already a string. But it's also harmless, since that call just returns x. :) However, the whole thing can be made simpler: string_underscored=''.join(underscored)
 
@PM2Ring whose 2:05? :P
 
@FrederickHong You might find this answer about recursing through nested dicts & lists (like you get from loading JSON) helpful: stackoverflow.com/a/41778581/4014959
@AndrasDeak Oops
Ok, 4:05 UTC. :D
I've just been writing code that does General Relativity calculations: photon trajectories around a black hole. So it's a bit worrying that I yammed up a simple timezone thing in chat. :)
 
things like terrestrial timezones are much too down-to-earth ;)
 
11:38 PM
Even without relativity, time conversions can be confusing. It's so easy to accidentally mess up a sign here or there.
There's this thing called the Equation of Time (EoT), which concerns the conversion from apparent solar time to mean solar time. The phrase refers both to the equation, as well as to the number you add or subtract to convert from one to the other. To increase the confusion even further, there's no consensus on whether the EoT is added to sundial time to get clock time, or vice versa.
 
11:54 PM
excellent convention
 

« first day (3948 days earlier)      last day (993 days later) »