« first day (2290 days earlier)      last day (2641 days later) » 
00:00 - 23:0023:00 - 00:00

12:05 AM
I don't know, sorry. Hopefully others will.
 
12:53 AM
cbg
 
@PM2Ring puppy is becoming a huge PITA
I've been struggling to set up an ssh server on it, and failing
and it all ties in with the "the user is root and why would you even want to know the password, let alone change it" philosophy
I'm seriously considering trying lubuntu instead
 
1:19 AM
yam it
I currently feel that I wasted hours of my life today in vain:/
 
@AndrasDeak Oh. :-( Sorry, I don't know what to suggest, I've never tried to do that. I assume you've checked the Puppy forum. You can set up a non-root user, the default is "spot" but I've never done that either.
 
yeah, I've googled for hours:)
there's spot and fido, but by the time I realized that I should probably set one of those up, I concluded that if a thing as simple as an ssh server eludes me I should probably stop before I get to the harder bits:D
btw puppy documentation sucks
 
Fair enough
 
I can only seem to find "click this button, very good" uninformative bits, and ancient forum threads with missing attachments
anyway, it did seem like a good path first, so thanks for the tip:)
 
The docs aren't so bad when you're used to them but they aren't well organized. And old stuff is mixed in with new stuff.
rhubarb
 
1:35 AM
rhubarb
 
2:02 AM
Can someone either please reopen this post or at least link a real duplicate SO thread to it?: stackoverflow.com/questions/41786467/…
Thank you
 
2:13 AM
@Vincenzzzochi I'm curious why you think that's not exactly the duplicate
 
DSM
2:34 AM
@WayneWerner: it's an okay dup, 'cause it shows what to do, but the answers bury the "why is this happening" part.
 
@WayneWerner Exactly what @DSM said. We know you can [:] the list, but the user is definitely new to Python and would not have understood that from the dup at all
 
DSM
3:02 AM
@wim: yeah, that pow Q is a little confusing. Title asks for x, then there's an equation for z which is wrong but I think is just meant to mean "something like", and then there's "x?"
 
 
5 hours later…
7:39 AM
Hi!
 
 
3 hours later…
10:29 AM
cbg
 
10:48 AM
cbg
 
cbg
 
11:19 AM
cbg
 
cbg
 
cbg
well sorry guys :D
I need to ask, does anyone know a simple service that I could install in Linux that would a) have user auth, b) file uploads via web browser ala box
 
phpfm
 
@Brandin hey no swearing :P
but yeah something like that
dunno if that has more holes than swiss cheese
 
Oops this is the Python room, I guess the other P word is not allowed.
 
11:31 AM
no, it is ok for this question, I am just a little worried about these php projects :D
 
I used that for access to shared hosts that had poor infrastructure (no SSH). When I was done I always got rid of it because it was just a temporary thing.
 
Hello
 
@Brandin yeah I guess it is fine behind another auth layer
trusted users
@Brandin doesn't that (no ssh) qualify as cruel and unusual punishment
anyone knows if winscp still sucks?
used to be slow as hell
with ssh
 
What is wrong with WinSCP? If there's a better tool I'll try it. But it always seemed to be the best so far.
 
@Brandin slow as in 20x slower transfer rates than scp
that wrong :D
it seems that they've done some new commits here...
@Brandin 20x slower transfer rates from the same network; linux + scp vs single file with winscp, can't believe it is windows at fault either :P
 
11:42 AM
Oh, I never noticed. I guess I'm just too patient. But I guess it may be fixed now?
 
might be but certainly was an issue before 2016
I don't remember trying it last year
and for comparison, it used to be faster to write the thing to usb stick, then move to a linux computer and upload from there
 
I probably won't upgrade until I notice the issue. I'm not a fan of upgrading software all the time. Wait until I need the new features, then upgrade and be prepared for new features + new bugs.
 
this has been there since the beginning of time.
linux uploads 1-3MB per second, winscp 50k <3
and then authors said "your computer is slow"
or something like that
" To add to this, I can do 3 or more parallel transfers and each one caps at 100KBps showing that not only can my computer and the server keep up with faster transfers, but that WinSCP can do multiple ones in parallel beyond the cap of 100KBps (or a fractional percentage of the total speed available). "
 
12:08 PM
Which tool is good for speed? I think rsync is pretty good if you want it fast.
 
well, all of them use ssh underneath nowadays
 
cbg :D
 
import time

while True:
    print("cbg")
    time.sleep(200)
 
12:29 PM
about import statement in python... i have seen a lot of people use next syntax:
import something
from something import somethingelse
why is that ? should not be easier to just do from s import se
 
@Danilo Which names do you want? Do you want both 'something' and 'somethingelse' ? Or do you only want 'somethingelse'?
 
@Brandin, wel i have seen in code importing a whole module to use only 2 functions. I allways thinking that that was remnant of some version before where from statement did not exist, or maybe it was a safeguard if from something import something else fails.
I mostly use from x import y,z,zz,zz.... but i was thinking maybe i am doing it wrong. so decided to see what nominal norm it is.
 
It may be a matter of style. You can write
import x
# ...
# use x.y
# ...
# use x.z
# ...
Or you can write
from x import y,z,zz,zz
# ...
# use y
# ...
# use z
But at some part of the code, maybe you forget that 'y' belongs to x. So maybe you want the choice of either writing 'y' or 'x.y'. Then you can do both:
import x
from x import y,z,zz,zz...
# ...
If x does not exist, both should cause ImportError, so I don't see how it could avoid errors.
 
12:46 PM
so it could be a safeguard ? makes sense ... i guess it is justified on over 1K lines of code.
I was thinking maybe py in earlier version (ex 1) from statement was not included so earlier generatins of py coders implemented that in their style to be compatible with first versions
 
Cbg
 
cbg
 
The "from" style is convenient and slightly faster than resolving x.y but it's a lot more readable to use the x.y form unless the y name is really distinctive.
 
so like classes and objects , if you have class dog , and object breed, if it is dog.breed it is descriptive more than just breed :D makes sense
 
If you import a lot of modules it's a PITA to remember where everything comes from.
 
12:55 PM
but then you should have a chains of dots if there are subclasses. wouldn't that fog up your code ?
ex x.x1.x2.xm1() == y.y1.y2+z.z1.zm3()
 
Also, using full names avoids name collisions, although that's mostly a problem with star imports
 
it is primarily opinion based. I personally prefer `import x` as I feel it is more convenient because one need not to scroll up the file to check the module.
However I also use `from x import y` where either x or y is too lengthy in order to clean the mess (huge variables) in rest of file. In order to prevent it, Python also has `from x import yyyyyyy as y` <-- I use it very rarely
 
It is a style question. In Qt applications I always write
from PySide.QtGui import *
from PySide.QtCore import *
 
^ which you should never do
 
Because I do not want to write nor read PySide.QtGui.QBlahBlah all the time.
It is my choice to do so. And if I work in a team, we make a style rule yay or nay.
 
1:00 PM
@MoinuddinQuadri you should not do from x import yyyy as y ?
 
In this case, all of Qt's names are already distinctive. QPoint obviously is a Qt type, so there's no confusion.
 
@Danilo You should not do from x import * . Check: Why is “import *” bad?
 
Also it would be nice if py has from x import yy,zz,dd map(y,z,d)
 
@Brandin use a proper IDE, like pycharm, and it will write unambiguous imports automatically.
 
@AnttiHaapala What do you mean, unambiguous imports?
 
1:03 PM
@Brandin say, you do from X import * and from Y import *, what is Z now?
 
holy hell pycharm has a lot of windows and buttons.... O.O no thanks , im sticking to notepad.

@MoinuddinQuadri red it , makes sense.
but there is allways empty dir() option
 
So how can I write my earlier example? I think it is just fine.
 
Star imports are evil and should only be used in special circumstances, like in an __init__.py file to amalgamate names from sub-modules. Or when your just mucking around
 
another thing is that if you write a module and do not pay attention to giving a proper __all__ it might pull in some crap that you never imagined.
 
The alternative, to write PySide.QtGui.QMainWindow and so on kills readability for me, so I don't do that.
But if we have a team and the style rule is to do it that way, then so be it.
 
1:08 PM
whenever i worked with a team we split workload to the minimum necesery and then everyone grabs a function or data type and codes. After that when we finish the mock project in part, we combine it and then use PEP to clean the syntax up.
it seemd easier for everyone to code how they are used to, but if you publicize it , it should be in some standard.
 
@Brandin I guess that's forgivable then, although it does mean your namespace gets loaded with all the names in those modules, including the ones your code never uses, and that's inefficient.
 
@Brandin , yeah why dont you just use ... from x import y if you are not using all functions from x module
 
@Brandin I don't use Qt (I learned GTK instead, but mostly use Tkinter these days, purely for answering SO questions) How about doing something like import PySide.QtGui as qtg ? That minimizes the visual clutter and avoids the namespace clutter. FWIW, it's a very common convention to do import tkinter as tk and import numpy as np
 
Yes, perhaps runtime efficiency goes down slightly. But programmer efficiency improves. Suppose I need to use a QPoint, but I haven't imported that. Well, I know I've got all the Qt types imported already, so just use it. It's much simpler for development.
If it is my choice, I would still say no. I'm too lazy to read or write qtg.QPoint, qtg.QMainWindow, qtg.QWidget, etc. Getting rid of the clutter is better. Even the 'Q' at the beginning of those names is sometimes annoying to me.
But it is a style choice. If the team says, "let's use qtg" then you should do that. It's better to be consistent.
 
1:29 PM
@Brandin Well, if you're doing GUI stuff it would be crazy to import stuff like QPoint one by one using from PySide.QtGui import QPoint, QOtherThing etc. And I guess you don't really care whether something comes from PySide.QtGui or from PySide.QtCore. OTOH, if you want to make your own QSpecialWindow it'd be nice if it were obvious that it was your class & not one of the imported ones.
Another option is to make a module that does all your Qt star imports and then you import that module. IOW, you have a module that just contains
from PySide.QtGui import *
from PySide.QtCore import *
And you import it with something like import MyQt as q. Then you've only imported 1 name into your script and you can do stuff like q.QPoint
 
Such a MyQt module might be a good balance. I'll probably continue import *, however, until I actually get burned by it.
 
I'm a little curious how much clutter those Qt star imports actually create. Can you go into a fresh REPL and do both of those star imports & then do len(dir()) ? I suspect the number will be well over 100. Tkinter is a pretty small GUI framework compared to Qt or GTK, but it pulls in around 130 names, IIRC.
@Brandin :)
 
Here's what I got
>>> len(dir())
4
>>> from PySide.QtGui import *
>>> from PySide.QtCore import *
>>> len(dir())
533
>>>
 
what only 529 more elements D: :P
 
As I said before, it's probably tolerable since the names are so distinctive. And Python dictionaries are pretty efficient, so cluttering the namespace isn't really that much of an impact on runtime speed. Of course it does increase RAM usage a little too, but that's probably even less of a concern.
@Brandin Thanks for that info. I have no idea how much that will slow down access of globals() but I guess it wouldn't be too hard to get a rough idea using timeit.
 
1:51 PM
Most of the run-time of a GUI application is not spent in the Python code, so I don't think you'll be able to measure a difference in a realistic application. Maybe if you have a tight loop doing some numerical calculation. But then you should ask yourself if Python is really the right choice.
Python is good for optimizing programmer efficiency, not CPU efficiency.
 
True
 
Thinking about dir(), I was curious about names starting with "_", so I wrote the following
[ s for s in dir() if s.startswith("_") ]
Is there a more functional way to write that, so I don't have to write s three times?
 
maybe filter( lambda s: s.startswith("_") , dir() )
i dont know if you just put filter( str.startswith("_") , dir() ) if it would substitute str with string from dir()
nope it does not
 
Try it!
I'm slow because I'm back on my phone
 
you could always make filterProcces function
i will post example for mapProcess i made
#map procces sequence
def mapProcces(proccesList,listToMap):

currentProcces = proccesList.pop(0)
listToMap = map( currentProcces, listToMap )

if proccesList != []:
return mapProcces( proccesList, listToMap )
else:
return list( listToMap )
so similar so you could use filterProces(filterstatementlist, list )
 
2:12 PM
How do you use that for example?
 
mapProcces([lambda x: x+1, lambda x: 2*x], [1,2,3])
 
exactly
sorry i did not reply sooner... toilet was calling
 
2:30 PM
BTW, that should be "Process". I wouldn't bother wrapping the return value in list(), let the caller do that if they need to.
Also, it doesn't need to be recursive, you can do that in a while loop.
 
I would prefer using itertools for this. It may make handling large lists better. I haven't timed it:
from itertools import * # for imap. I imported * just to annoy people.

def imapProcess(processList, m_prev):
    currentProcess = processList.pop(0)
    m_cur = imap(currentProcess, m_prev)

    if processList != []:
        return mapProcess(processList, m_cur)
    else:
        return m_cur
 
@PM2Ring i wraped in list since i was using it in py2.7 and py3.5. maybe it could have additional parameter, mapProcess(procesList, m_prev, mapPR = map) so now in mapPR you could use imap, map or anyother maping tool avaiable ?
i figured that is better to be recursive than in while loop since it is finite list, so recursion seemd logical. but maybe while is better
 
I'd do it like this:
def map_process(processes, seq):
    for proc in processes:
        seq = map(proc, seq)
    return seq
 
maybe passing all that version trough timeit could be usefull
 
And that way you avoid .pop(0) which is inefficient, since it has to move all the other list elements down.
 
2:43 PM
ok. lets try it :Dd
 
I'm currently using a Chromebook, in guest mode, so I can't do a lot. :) I can run code in repl.it, but it's slow!
 
def mapForLoopProcess(processes,seq,funct = None):

funct = map if funct==None else funct

for procElem in processes:
seq = funct( procElem, seq )

return seq

a = mapForLoopProcess( [str,str.lower,str.title,str.upper,str.lower], "one,two,three,four".split(",") )

py2.7 : 100000 loops, best of 3: 2.72 usec per loop
py3.5 : 100000 loops, best of 3: 4.67 usec per loop
a = mapForLoopProcess( [str,str.lower,str.title,str.upper,str.lower], "One,Two,three,FOUR".split(","), filter )

py2.7 : 100000 loops, best of 3: 2.76 usec per loop
py3.5 : 100000 loops, best of 3: 4.23 usec per loop
def mapWhileLoopProcces(processes,seq,funct = None):

funct = map if funct==None else funct

while True:
currentProc = processes.pop(0)
seq = funct(currentProc, seq)
if processes == []: break
return seq
a = mapWhileLoopProcces( [str,str.lower,str.title,str.upper,str.lower], "One,Two,three,FOUR".split(",") )
py2.7 : 100000 loops, best of 3: 2.8 usec per loop
py3.5 : 100000 loops, best of 3: 5.96 usec per loop
a = mapWhileLoopProcces( [str,str.lower,str.title,str.upper,str.lower], "One,Two,three,FOUR".split(","), filter )
py2.7 : 100000 loops, best of 3: 3.89 usec per loop
py3.5 : 100000 loops, best of 3: 6.51 usec per loop
def mapRecursiveProcces(processes,seq,funct = None):

funct = map if funct==None else funct
currProces = processes.pop(0)
seq = funct(currProces, seq)

if processes != []:
return mapRecursiveProcces(processes,seq,funct)
else:
return seq


a = mapRecursiveProcces( [str,str.lower,str.title,str.upper,str.lower], "One,Two,three,FOUR".split(",") )
py2.7: 100000 loops, best of 3: 2.61 usec per loop
py3.5: 100000 loops, best of 3: 5.27 usec per loop
a = mapRecursiveProcces( [str,str.lower,str.title,str.upper,str.lower], "One,Two,three,FOUR".split(","), filter )
py2.7: 100000 loops, best of 3: 2.71 usec per loop
py3.5: 100000 loops, best of 3: 7.93 usec per loop
now i honestly don't know how to stress test this ...
and this is done in win7 , 64 bit, on 32 bit py intepreter
 
3:01 PM
I'm quite surprised that the recursive version looks faster. And I'm very surprised that Py3.5 is significantly & consistently slower than Py2.7.
 
my expirience is that it is allways slower, except lambda functions... it is close call when i timeit that type
 
Comparing while to for sounds like a micro-optimization to me. If a recursive call seems clearer, use a recursive call.
.pop(0) is fine in this case, because the process list is small.
 
yeah... but i think the best solution would be stress testing and then optimize for size of list
 
However, you really should be creating the function list and the string list in the setup phase of the test, not on every timing call. Sure, you're passing the same args in every version, but you should try to minimize other code in the timing phase otherwise the time taken by the code we're interested in can get swamped by the other stuff.
 
If you're spending too much time worrying about Python's efficiency, I think you're doing it wrong. Have a reasonable data structure and reasonable performance, and it's fine. If you need more than that, move that part to a lower level module. That's what numpy does for example.
 
3:09 PM
@Brandin True. But still, the docs warn that pop(0) is expensive. FWIW, in Python 3 instead of head=seq.pop(0) you can do head, *seq = seq or head, *seq[:] = seq if you need to mutate seq rather than replace it.
 
@PM2Ring .... whaaat ? O.o
@Brandin well i could rewrite it with a little more time and retest it. By why do you think that worrying about Py efficiency is wrong ?
 
@Brandin Fair point. Generally, readability trumps minor differences in efficiency
OTOH, it's nice to be aware of what's efficient & what's not, so you make good choices while coding. I'm not suggesting that people waste time performing micro-optimizations, especially during development. The time to optimize is when you have working code that you can benchmark against real data so you can identify the actual bottlenecks.
 
@Danilo Presumably you are writing Python in order to write clear code. If you go back and replace all the clear code with stuff that happens to execute a little faster in the current Python interpreter, then it defeats the whole point of writing Python in the first place.
 
From en.wikipedia.org/wiki/Program_optimization#When_to_optimize "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%" -- Donald Knuth
 
@PM2Ring there is hope, I could get ssh working with another server:P
 
3:19 PM
@AndrasDeak Excellent!
 
unfortunately the lure of the OS in RAM and minimizing USB IO is too much to give up this easily:D
 
For example, in this case, you take a list of processes and then use .pop(0) to remove an item from the front. Of course, this is not optimal. If you were overly concerned about efficiency, you could require your users to pass in a reversed list, so that you can pop from the end, instead. But writing a list backwards is not as convenient to use.
 
readability first, speed later.
 
Since the list is presumably no more than 100 items, I think .pop(0) is just fine for example.
 
I googled for quite a while but all the other options I could find would've led to a USB bottleneck
 
3:22 PM
@Brandin .pop is great when you need to mutate the original list. But if the list is large, shifting the elements is relatively expensive compared to just building a new list by slicing the old one.
And that sort of thing generally doesn't change much from version to version.
OTOH, they did optimize string concatenation for strings upto a 1000 chars or so for the special cases of a = a + b and a = b + a, so building a string by concatenation in a loop can be faster than using .join. OTOH, if you're working with large strings, you still do need to use .join.
@Brandin Or reverse the list yourself. Or use a deque. So much for there being one obvious way to do it. But maybe it's because I'm not Dutch. ;)
 
Yes, but my point is you don't need any of that in this case, because the list is small. If the list gets up to thousands of elements, then you can consider optimizations.
 
@AndrasDeak Yeah. Having the whole OS in RAM is awesome. It makes a clunky old machine feel like it's got a SSD, only faster. ;)
 
recbg
I am a terrible teacher
 
@Brandin Oh, I fully agree. Assuming the list is small... I guess there are scenarios where you might have a huge list of functions you want to apply to the data list, but in that case you'd expect the processing to take time anyway.
@khajvah [citation needed]
 
I was trying to teach my little bro programming (8 years old)
I was too enthusiastic so I introduced too many concepts
 
3:32 PM
how did that go :D :P
 
I might need a simpler language
 
ahahahahhahahahaha ... so know the filing :D never know where to start to make student love it, and that student has effictiancy quickly :D
make him a console game
and make him redo it
 
that's gonna be hard
 
@khajvah Apologize for getting him confused, and tell him that you can try again when he's ready, starting from scratch. And only teach him enough to do something really basic, like print a multiplication table. Yes, it's boring, but remind him that you need to start small & build up, otherwise it gets confusing.
 
print multiplication table is nice
thanks for the problem
I will write down a few practice problems
from automate boring stuff with python
 
3:39 PM
No worries. I've successfully used it many times when introducing people to coding. And I'm pretty sure it was one of my first programs ever.
In fact, whenever I learn a new language it's one of the first programs I write, after "Hello, world" (they didn't have "Hello, world" when I first learned to code ;) )
 
Hey guys. What's the best book for advanced programming in python?
 
Whichever one is relevant to your advanced topic.
 
Hacking, socket programming
 
answear without asnwearing :D :P

first learn networking if you allready haven't
protocols, network systems etc etc
and dont watch hacker movies :D :P
because to use sockets you need to know what IP/TCP protocol is, what is IP, PORTS, MAC adresses , UDP, FPT etc etc
 
4:06 PM
I like Beej's Guide to Network Programming. Examples are in C, as I recall, but the stuff is pretty well explained and entertaining enough to read.
 
4:38 PM
@Danilo I know this concepts already. I want to learn advance network programming with a good book
@Brandin I hate C.
 
It's been a while since I looked at it. But if your level is advanced, I think translating them to Python shouldn't be too hard. The socket APIs are similar.
 
@Matarata read the docs
 
By the way, saying "I hate X", where X is a programming language, is only useful as stress relief to solve a problem. For example, I may encounter some problem with a Python program and in frustration, say "I hate Python", and then solve the problem. If, however, I think about solving a problem, and then say instead "I hate Python" as an excuse not to even try it, then that's no good.
 
@PM2Ring I translated Automate boring stuff with python problems and it seems to be working :D
@Brandin what if x == "PHP"
 
Then it applies even more. I worked with PHP professionally before and had to say "I hate PHP" multiple times per day to keep my sanity.
 
4:51 PM
@khajvah Great! How good is your little brother's English?
 
The problem I've noticed with Python books, is that almost all seem to talk to you like you are a beginner with programming. Older books or books that use other programming languages don't tend to do that in my experience.
 
Well, the official Python tutorial assumes that Python isn't your first language, so maybe all those books are compensating.
 
The Python tutorial is good as a reference, since it is organized by language feature. But reading it like a book seems strange to me. I have tried and couldn't get through it.
But if you forget the syntax for, say, dictionaries, by all means go to that section in the Python tutorial.
 
Really? I haven't tried reading through recent versions, but I first started on Python by working through the tutorial (it might have been 2.3 or 2.4, although I briefly looked at Python 1.4).
 
Thanks guys for help. I guess i won't get any book.
 
4:59 PM
@Matarata Come back when the room is busier. Others may be able to recommend a Python socket book.
 
You can try Violent Python. I notice it has good reviews on goodreads. One of the posters comments that it focuses on using APIs, rather than how they are implemented. But on the other hand, the answer to that problem should go without saying. Use the Source.
 
@Brandin You said all of the books are for beginners and i think thats true.
 
I guess it makes sense to start from scratch in an introductory Python programming book. It's becoming a very popular choice of first language. And even if you do have prior programming experience it's a Good Idea to learn Python's data model on its own terms, since it's so radically different from the data model used by most other languages.
 
@PM2Ring Didn't know that.Cool.
 
@PM2Ring he understands keywords but not the error messages
He picked up boolean logic very easily
I was surprised
Evaluates fairly complicated expressions
By just explaining for 5 minutes
 
5:11 PM
Fair enough. Python error messages can be pretty cryptic even for native speakers of English :-)
@khajvah Sounds like he's a natural programmer
 
Which error message is cryptic?
 
@Matarata Understanding the data model is important. You can pretend that Python works like other languages most of the time, but when it doesn't it can be bewildering.
I just answered a question because the existing answer is misleading in regards to the data model stackoverflow.com/questions/41793026/python-crash-course-q8-10
Anyway, it's getting very late here so I better say rhubarb
 
5:38 PM
cbg
im having some problems with module `pymorphy2`. While using its `MorphAnalyzer().parse` and `inflect` the `Parse()` object, getting that error:
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
beg.inflect('gent')
File "C:\Program Files\Python35\lib\site-packages\pymorphy2\analyzer.py", line 32, in inflect
res = self._morph._inflect(self, required_grammemes)
File "C:\Program Files\Python35\lib\site-packages\pymorphy2\analyzer.py", line 294, in _inflect
possible_results = [f for f in self.get_lexeme(form)
actually im not sure if it is problem with module. latest commit was on Nov 27, and no issue reports. inflect() method is necessary for work, and I dont know what to do
 
DSM
5:56 PM
@MaxLunar: looks to me like inflect is expecting a set (not the plural of the argument required_grammemes), not a string.
Just typing "inflect" into the search bar in the git repository for the code (e.g. this) shows that I'm probably right. See their test example:
17      def test_inflect_valid(morph):
18	    p = morph.parse('стреляли')[0]
19	    assert p.inflect(set(['femn'])).word == 'стреляла'
 
let's try
what should assert do if its correct/incorrect?
 
DSM
Wait, they even show an example right in the documentation!
>>> butyavka.inflect({'gent'})  # нет кого? (родительный падеж)
Out[13]:
Parse(word='бутявки', tag=OpencorporaTag('NOUN,inan,femn sing,gent'), normal_form='бутявка', score=1.0, methods_stack=((<DictionaryAnalyzer>, 'явки', 8, 1), (<UnknownPrefixAnalyzer>, 'бут')))
>>> butyavka.inflect({'plur', 'gent'})  # кого много?
Parse(word='бутявок', tag=OpencorporaTag('NOUN,inan,femn plur,gent'), normal_form='бутявка', score=1.0, methods_stack=((<DictionaryAnalyzer>, 'явок', 8, 8), (<UnknownPrefixAnalyzer>, 'бут')))
This doc page was literally the first page returned by googling for "pymorphy2 inflect".
 
Ah crap. I should put tags in the set, not string. Sorry for consuming your time
 
DSM
@MaxLunar: the assert is just part of their tests, verifying that it returns what you expect. If you're just calling the function, you don't need it.
 
nope, I wanted to ask whether assert should return something?
>>> def test_inflect_valid(morph):
... p = morph.parse('стреляли')[0]
... assert p.inflect(set(['femn'])).word == 'стреляла'
...
>>> test_inflect_valid(morph())
>>>
 
DSM
6:05 PM
I suggest reading up on what the assert keyword does; I could tell you, but it sounds like you could use some practice reading documentation. ;-)
 
done. It only raises AssertionError if example didnt passed the test.
 
Guys, is there a way I can do
`myvar=if(something): 2; else: 3`
instead of
if(something): myvar=2; else: myvar=3;
 
DSM
That's called a "ternary expression", and is written in python as
myvar = 2 if something else 3
 
thanks. I assume this also works with elif correct?
 
DSM
Nope.
 
6:15 PM
oh
ok ok, thanks so much! I learned something :)
 
@DSM wow, didnt knew that I can do this too.
 
@MaxLunar in case you are interested
http://stackoverflow.com/questions/2802726/putting-a-simple-if-then-statement-on-one-line
 
it is possible to create range() with items like floats 0.001, 0.002, 0.003 ... ? In fancy way, ofcourse
so it wouldn't take too much memory
when compared with list
 
6:31 PM
genexp: (n/1000 for n in range(1,nmax+1))
recbg
 
thanks.
 
 
1 hour later…
7:35 PM
user image
3
 
Hello.
New to Python, new to programming, new to StackOverflow and new to this chatroom.
Is it OK to ask simple a question here?
 
7:59 PM
@GitGud cbg, this question is answered in our room rules; TL;DR: yes, you can ask your simple question here.
 
Oops, broke a rule already. I'm busy at the moment, but I'll ask later. Thanks, @AnttiHaapala
 
8:20 PM
Don't know who this Kim is, but she seems popular
 
What the shit? I didn't type "xD"
 
@PM2Ring I forgot to tell you the most culturally relevant detail: the substitute ssh server I found is called dropbear:)
 
Oh. On my screen it showed that I sent that message, now it shows it was Byte.
 
yup
 
8:35 PM
Question: I saw a solution to [Python Challenge 3](http://www.pythonchallenge.com/pc/def/equality.html) that starts by importing the data as shown in the code below.
>>> import urllib.request
>>> import re
>>> html = urllib.request.urlopen("http://www.pythonchallenge.com/pc/def/equality.html").read().decode()
>>> data = re.findall("<!--(.*?)-->", html, re.DOTALL)[-1]

I don't understand the last line.

The definition of .findall from docs.python.org is:
Return all non-overlapping matches of pattern in string, as a list of strings. The string is scanned left-to-right, and matches are returne
For instance findall("ab","abbaaabbbbaaaaa") returns ["ab", "ab"] which seems to comply with the documentation.

But in solution to the challenge, the output isn't repetitions of "<!--(.*?)-->". I assume this has something to do with either DOTALL or the [-1] index. But I can't tell how. I don't understand the documentation for DOTALL.

Can anyone help me understand why the solution I found online works?
 
@GitGud that re.findall would find all html comments in the source; then -1 returns last of them.
DOTALL makes . also match a new line; without DOTALL, . wouldn't match the newline character and the regex would fail to match the actual multiline-html comment
so basically the regex matches literal <!-- followed by any number *(but the least amount possible *?) of any characters . (including newlines - DOTALL), followed by literal -->.
the stuff inside is captured as the group 1 (those parentheses ( and ))
 
@AnttiHaapala I noticed that it fetches the last comment, but I don't understand how. I got why [-1] works.
I reread the DOTALL documentation and for some reason now I get it. It's like * on UNIX, right?
 
yes and no ... :D
= that is, no.
.* is the "Unix" * - but mind you this regular expression syntax also comes from... Unix.
 
I think I need to get back a bit. What is this regex you speak of?
 
:D
A regular expression, regex or regexp (sometimes called a rational expression) is, in theoretical computer science and formal language theory, a sequence of characters that define a search pattern. Usually this pattern is then used by string searching algorithms for "find" or "find and replace" operations on strings. The concept arose in the 1950s when the American mathematician Stephen Cole Kleene formalized the description of a regular language. The concept came into common use with Unix text-processing utilities. Today, different syntaxes for writing regular expressions exist, one being the...
 
8:49 PM
(By the way, thank you).
 
not for the faint of heart
 
@AndrasDeak :D
there are people (python programmers) who think that Kleene is the Antichrist, and writing regexes is akin to satan worship :D
well, I am not one of those :D
the thing is, the extended syntax is rather awkward :(
 
I'm fine with regexes (having taught myself perl as one of my first languages), but I see how easily it's used to shoot yourself and others in the foot
 
I need a little more time to digest your explanation. I need to go do something else, but I'll get back on it ASAP.
I undersood what a regex is, it is the pattern input in the findall() documentation.
 
a regex is a much larger and more ubiquitous concept, it's present in a lot of languages
 
9:00 PM
@GitGud "regular expression" is an expression that can describe a "regular language"
actually the "regular" expressions of Python are a superset of the strict regular expressions
anyway, the regular language / regular expression thing also goes to linguistics...
 
 
1 hour later…
10:19 PM
Cabbage.
@AnttiHaapala I just realised that (.*?) is steps in as whatever is between <!-- and -->, but I can't conciliate this with your explanation nor with the documentation explanation.
 
'.'
(Dot.) In the default mode, this matches any character except a newline. If the DOTALL flag has been specified, this matches any character including a newline.
*?, +?, ??
The '*', '+', and '?' qualifiers are all greedy; they match as much text as possible. Sometimes this behaviour isn’t desired; if the RE <.*> is matched against <a> b <c>, it will match the entire string, and not just <a>. Adding ? after the qualifier makes it perform the match in non-greedy or minimal fashion; as few characters as possible will be matched. Using the RE <.*?> will match only <a>.
(...)
Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group; the contents of a group can be retrieved after a match has been performed, and can be matched later in the string with the \number special sequence, described below. To match the literals '(' or ')', use \( or \), or enclose them inside a character class: [(] [)].
the ... means "something inside the parentheses..."
 
Ohh, I was missing the syntax for the re ... module? Is that what it's called?
 
yes
@GitGud the regex101.com is rather good for playing with regexes.
the s in flags is synonymous with DOTALL...
 
Thank you very much, Antti. I'm sure this will be more than enough to fully understand this.
 
if you remove the s flag, the regex will match the first but not the second, since the second contains a newline character.
and if you remove ?, you get the longest match instead of shortest match for the .*
 
10:32 PM
What if one wants to match the following sequence of characters: (.)
Wouldn't it just match everything?
 
it would match one character, and capture it as a group;
you'd need to escape each special character by preceding it with \
i.e. \(\.\)
 
Got it.
 
Instead of backslashes, you can use a capture group as a way of matching metacharacters. For example, to capture dollars and cents, you could write
\$[ ]{0,4}([\d,]+)[.](\d+)
Literal $, 0-4 spaces, group 1: one or more digits or commas, literal ., group 2: one or more digits.
 
00:00 - 23:0023:00 - 00:00

« first day (2290 days earlier)      last day (2641 days later) »