« first day (3299 days earlier)      last day (1633 days later) » 
05:00 - 17:0017:00 - 00:00

5:45 AM
cbg
 
 
6 hours later…
12:03 PM
Cabbage
c = input("Enter a String: ")
indlist=c.split(" ")
flist=[]
print([flist.append(num) for num in indlist if num not in flist])
What is wrong with the above code?
The last line just spits out a list of none values,
I am trying to take a list of strings as user input and return a list with non duplicate strings
 
for num in indlist:
    if num not in flist:
        flist.append(num)
This works however
@AndrasDeak umm... I know that but how is it related to this? I am not doing an assignment in my list comp
have I misunderstood how list comp works?
@AndrasDeak BTW really cool site , I am going to go through all the questions :-D
 
#This code:

results = []
for item in seq:
    results.append(f(item))

#is equivalent to this code:

results = [f(item) for item in seq]

#Therfore, this code:

print([flist.append(num) for num in indlist if num not in flist])

#is equivalent to this code

results = []
for num in indlist:
    if num not in flist:
        results.append(flist.append(num))
print(results)
 
@Anarach you are storing in each iteration of the list comp the result of flist.append(num)
 
If you're trying to identify only the unique items in indlist, a list comprehension isn't a great tool for that, because the body of the list comp can't check the contents of the list being created, while it's being created.
 
12:15 PM
@Anarach so yeah, it seems you did
 
Consider using a set, for example flist = list(set(indlist))
Or perhaps flist = list(dict.fromkeys(indlist).keys()), if order matters.
 
@Kevin Oh... This makes a lot of sense..
 
Your code was actually pretty close to producing the right output, albeit a bit inefficiently. If you had split the last line into two lines:
[flist.append(num) for num in indlist if num not in flist]
print(flist)
 
@Kevin Python Never ceases to amaze me
 
... Then it would have worked.
But.
Finding unique elements in a collection by checking if they're in a result list before appending them to the result list is slow, around O(N^2). There are faster approaches, two of which I have already named.
 
12:21 PM
@Kevin OMG! this worked actually , but then I was like , I only added a print statement so that shouldnot be the issue
 
And you almost never want to use a list comprehension if you're not going to assign the result to something and use it for a meaningful purpose.
If the part before the for always evaluates to None, that's a red flag
 
@Kevin I shall etch these into somewhere I remember always
@Kevin So... I should Only use list comp if I want some specific output , instead of doing some operation on an existing list using list comp.
 
Basically yeah
 
Huh... never knew that lol.. I discovered list comp and was like , I shall use this for everything..
 
@Anarach how do you feel about regular expressions? ;)
 
12:27 PM
That's a common response to discovering list comps
 
@AndrasDeak Learning to read Mandarin is probably less painful than RegEx
@Kevin Poor Man's "Deep Learning" , I suppose :-P , Now a days , everyone wants to use DL for everything. Especially college grads..
 
@Anarach also what not to do: use it to print or other kinds of side-effects as a one-liner loop
embrace for loops
 
@AndrasDeak Yeah , Too bad learnt it the hard way.. Actually , There was this one guy sitting next to me who proposed a for loop based solution which worked but I rolled my sleeves and was like , Hold my Beer.
Now , I just have to go tell him to unhold my beer :-P
 
I think it's a natural part of the learning process to think "how can I apply this to absolutely everything?" when faced with a cool new feature. First you learn how it works, then you learn what it's good for. No point doing it the other way around.
 
agreed!
 
12:33 PM
and then there are assignment expressions
 
What in the holy mother is this new operator? What? new operator?
 
Hey now. I've had a 100% success rate for using the walrus operator in a useful manner since its introduction. All one times.
 
@Kevin Ha ha ha walrus operator ha ha ha nice one
 
@Anarach yeah but many people don't like it, because it offers small benefit in a few very specific use cases at the cost of being able to be abused horribly in a lot of misguided non-use cases
 
@Anarach That's what the documentation calls it.
 
12:35 PM
Can someone give a one line explanation of what it does.
 
Are you familiar with the C language?
 
@AndrasDeak Sort of , I studied in school , thats it
 
consider the common mistake:
 
@Kevin "the walrus operator" no kidding, they do..
 
if (time_to_nuke = 1){ /* uh-oh! */
    kill_all_humans();
}
now you can do that with python \o/
 
12:37 PM
Normally, you can't put assignment statements inside larger expressions, because statements can never go inside expressions. 2 + (a=4) has never been possible, for example. Assignment expressions are like assignment statements, except they can go wherever an expression can go*, so now 2 + (a := 4) is possible.
 
(yeah, not really, but meh)
 
(*with various exceptions that make it illegal wherever the result would be ambiguous. I can't give any examples because the rules are themselves ambiguous)
 
(*also even the implementation defies the PEP sometimes)
 
@Kevin Sounds like the Telephoto lens on smartphone, Looks cool but I would probably never use it
@AndrasDeak Neat example..
if env_base := os.environ.get("PYTHONUSERBASE", None):
    return env_base
This example is cool through..
 
The only thing I plan on using it for is with regex
 
12:41 PM
Would work well for sockets I guess, dont have to look in every time before using
 
#annoying
m = re.match(pattern, s)
if m:
    print("match found")
    print(m.group())

#not annoying
if m := re.match(pattern, s)
    print("match found")
    print(m.group())
 
@Kevin wow... Nice one
 
@Anarach Doesn't dict.get use a default second argument of None anyway?
 
@Anarach that's one of the few legit use cases
 
Meaning a simple os.environ.get("PYTHONUSERBASE") would be just as good for your purposes (though perhaps a little less explicit).
 
12:55 PM
That example is from python.org/dev/peps/pep-0572/#site-py and ostensibly the CPython source. Strange that it would be unnecessarily wordy like that.
Maybe there's an actual justification in the code itself. I'm looking it up now
 
I still haven't played with it, but does it mean instead of doing my_set = set(some_list) then doing filtered = [el for el in my_list if el in my_set]... you could do: filtered = [el for el in my_list if el in (my_set := set(some_list))] or something?
 
@JonClements uh, aren't those different things?
 
@JonClements I mean, the latter would recreate the set in every iteration. So same result, but much slower.
filtered = [el for el in my_list if el in set(my_list)], right?
 
that's what I'm pondering... in set(some_list) would definitely be wasteful but would in (my_set := set(some_list)) do it once or just do the same?
 
12:58 PM
@JonClements the same
all it does is assign that expression to my_set in each iteration, and allowing that name to leak out from the comp
 
Let's test it empirically.
>>> def show(x):
...     print(x)
...     return x
...
>>> some_list = [1,2,3,2]
>>> my_list = [1,2,4]
>>> filtered = [el for el in my_list if el in (my_set := show(set(some_list)))]
{1, 2, 3}
{1, 2, 3}
{1, 2, 3}
Result: set was called three times, once for each element of my_list
 
Thanks Kevin...
makes sense I guess
 
The behavior you were hoping for reminds me of C++'s static variables, which only execute the first time they're encountered, and on all subsequent executions remember their previous value
(extremely fuzzy recollection)
That would be a fun feature for Python although it might be tricky to define how long the static variable should remember its old value
 
I think static variables have to be set during compile time
 
Yeah.
Well, we've already got keywords that mark variables as special at compile time: global and nonlocal. So we may as well add another one
 
1:08 PM
I was pondering - although not something I'd use, was if it could be something akin to: list(filter(lambda el, my_set=set(some_list): el in my_set, my_list))
 
@Kevin but the values are set during compile time
changing them during execution would defeat the purpose of staticness, right?
 
I thought they could be mutable (but not reassignable?) under certain circumstances. I'll see if I can find a citation.
 
I've been trying to decide either way but this is too hard to google
 
I vaguely recall that they were good for memoization, so there's got to be some mechanism of statefulness there
 
@Kevin yeah, that would be a strong sign
 
1:11 PM
In any case the feature I'm thinking of is conceptually distinct from Java's static, which is more akin to a widely visible constant. I think.
 
oh, I may be confusing static and const!
> (C99, 6.7.8p4) "All the expressions in an initializer for an object that has static storage duration shall be constant expressions or string literals."
OK, I know too little about C for this
 
Here's an example, in the first code block of riptutorial.com/cplusplus/example/24780/…. static std::map<int, int> values; is local to the fibonacci function, and (I assume) not visible in any other context. It stays alive in between calls to fibonacci, and values get added to it as necessary.
Perhaps I only imagined the "only executes the first time they're encountered" part, since nothing is being executed on the static std::map<int, int> values line, per se
 
OK, so it's a persistent variable, and can be mutated, and it makes sense because I did think of const instead
 
I don't know if static typename variablename = initialValue(); is legal syntax or not
 
I don't think so. (Give or take whether this is a "syntax" issue)
 
1:16 PM
Ah probably not legal syntax then
 
Unless initialValue is declared as const? Hmm...
in any case we've yet again succeeded in getting unreasonably deep in a side-tunnel in this rabbit burrow metropolis
 
I was wondering why a rabbit with a pocket watch just ran past me...
 
During my C++ days, I didn't dislike the static feature... Whenever I need to write a function with persistent state, I wish I could somehow declare that within the body of the function, just for conceptual clarity
 
apparently he's worried about being late...
 
#yuck, global variables
_cache = []
def frotz(x):
    _cache.append(x)
    return x*2 + 1

#yuck, mutable default arguments
def frotz(x, _cache=[]):
    _cache.append(x)
    return x*2 + 1
Dear Python, please let me do static _cache = []
 
1:21 PM
perhaps static would be equally yuck, you just don't see it
The main problem with globals and mutable defaults is that they spaghettify code, right?
 
Partially agree. Persistent stateful functions are powerful footguns so we shouldn't be encouraging their use by making them easier to create.
 
Hmmmm... how about using a generator that takes input with yield? :)
 
But I still do need to make them every once in a while, and the phantom limb where static should be twinges every time
 
>>> def frotz_gen():
...     _cache = []
...     y = None
...     while True:
...         x = yield y
...         y = 2*x + 1
...         _cache.append(y)
...
... frotz = frotz_gen().send
... frotz(None)

>>> [frotz(k) for k in range(3)]
[1, 3, 5]
much better :P
 
When taking a user input why does python default to assigning values as str instead of the appropriate int or float type
 
1:31 PM
@Anarach because python refuses to guess
 
It's a design choice, it's better that a programmer needs to actively think about what datatype they need to work with
 
and python 2 used to eval things on input, and that was a huge vulnerability (and liability)
 
I mean , if users want a string "10" they can enter it in double quotes
 
because functions that always return the same type are easier to use without bugs than functions that can return any one of 10 different types
 
1:32 PM
cbg
 
users aren't programmers
tell a user "you have to wrap this in quotes" and see how they respond
 
I'd be shocked to find users who was clearly aware about datatypes and were not programmers themselves
 
@Aran-Fey Ha.. totally forgot .. :-P
 
Heck, i am NOT shocked to find progammers who end up mixing datatypes so..
 
@ParitoshSingh Some of us took awhile to decide to be programmers, lol.
 
1:42 PM
Even back in the 2.7 days, there wasn't a built-in way to do "get user input and try to make it into a number or whatever, and leave it as a string otherwise". If you used input, then it would work on 10 but crash on Hello World
 
In that case, how does python internally assign data types to variable? it does something similar right? We dont explicitly mention the datatype while assigning a variable
 
@Kevin but it would not crash on __import__("os").system("echo h4xx3d")
@Anarach when you write 2 in your code you're really saying "an int literal with value 2"
same for every other built-in, otherwise you're more or less explicitly instantiating a given type
 
For certain definitions of "variable", a variable does not have a type. You can't tell Python "a is a string and will always be a string, forever". Nothing can stop you from doing a = "foo"; a = 23
 
@AndrasDeak Right!
 
An object has a type. An object knows what type it has because that information is stored in the header of all Python objects. Uh, I think.
import ast
def infer_type(s):
    try:
        return ast.literal_eval(s)
    except SyntaxError:
        return s

while True:
    x = infer_type(input("Enter a value: "))
    print(x, type(x))

"""
Sample output:

Enter a value: 10
10 <class 'int'>
Enter a value: 10.0
10.0 <class 'float'>
Enter a value: Hello, World!
Hello, World! <class 'str'>
Enter a value: "10"
10 <class 'str'>
"""
If you really want a type-guessing input, then making one isn't too hard^
 
1:57 PM
@Kevin "Isn't too hard" is an understatement.
 
I saw McG runs this Pyparsing Library , I really cant get my head around as to why would I need it! is there a dumb way to explain?
@Kevin Ha Ha true!
 
@Anarach It's useful for...*drumroll*...parsing strings
 
But regex does that
? am I missing something here?
 
Regex can't parse all kinds of strings, though
You can't write a regex that finds all instances of X in a string, except for Xes that appear inside parentheses, for example.
 
2:00 PM
@Anarach CFLs.
 
@Dair compact fluorescent lamp ?
 
@Anarach Context Free Languages.
 
Basically, a regex cant do everything that pyparsing can
 
@ParitoshSingh So its an alternative to Regex then?
 
Now, the next question in your brain should be "like what". And then we spiral into madness and all that good stuff
 
2:02 PM
PyParsing is an alternative to regex in the same way that a screwdriver is an alternative to a hammer
 
@Kevin From @ParitoshSingh 's reply , I assumed it would be a swiss army knife than a screwdriver or hammer
 
Regex is for extracting or replacing substrings, or for validating strings. Pyparsing is for parsing strings.
 
@Anarach Referring to the theoretical defs of regexes and cfgs (context free grammars), Regex can be emulated by CFGs but Regexes cannot emulate CFGs.
 
Hmm, perhaps my metaphor is bad. A parser can do everything that a regex can do, but a regex can't do everything a parser can do.
 
Um.. where would I want to Parser? Like in real projects..
 
2:04 PM
@Anarach Have you ever wanted to make a programming language?
 
When programming a language, like say, python.
 
Holy mother of God.
 
@Anarach I wrote a simple simulation program and I use pyparsing to parse the input file
the way I'm using it it's probably a glorified configparser
 
Last week I wrote a parser for a Frankenstein's Monster of a serialization format that wasn't quite JSON, and wasn't quite a valid Python literal. stackoverflow.com/questions/58561257/…
 
Regardless though, you can "parse" a lot of things. writing languages is just one good example that is clear.
But there's html parsers out there, math expression parsers, date parsers, etc
 
2:05 PM
@ParitoshSingh Parser parsers.
 
xml, yaml, csv, for instance
 
Indeed!
 
I wrote a parser for KevinScript, albeit in the wordiest possible way
 
Something that requires breaking down a complex input into tokens for further processing. Might be over simplified, but i hope you get the idea.
 
but not HTML... never HTML
 
2:06 PM
@inspectorG4dget Oh.. Now this sounds interesting.. Not many tutorials on youtube for this,..
 
It should be noted, you can kind of use regexes for parsing languages if you do it in conjunction with something like recursive-decent parsing.
but then you kind of go into a rabbit hole.
 
I don't understand everyone's obsession with learning to program through youtube videos. Seems very counterintuitive to me
 
@ParitoshSingh This is probably the most dumb person friendly definition to a parser
 
I mean... you don't learn to ride a bike by watching youtube videos
 
2:08 PM
@inspectorG4dget kids these days :P
 
@AndrasDeak s/XML/XHTML. XML can in fact be regex parsed, no?
 
I'm pretty sure SO main page wouldn't be half of what it is (today) if people learned from letters still
 
Parsers are quite frequently paired with lexers, which often use regex to turn raw string data into a stream of tokens. In that sense, parsers and regex often go together.
 
@inspectorG4dget no idea
 
@AndrasDeak I need a rocking chair and a shotgun. "Get off my lawn"
 
2:09 PM
@inspectorG4dget Rule of thumb: anything that can be arbitrarily nested can't be parsed with ordinary regex. XML can be arbitrarily nested.
 
@inspectorG4dget challenge accepted. falls off the chair immediately. or..hmm..perhaps not.
 
Do we agree whether recursive regex is still regex? Asking as someone who's never seen recursive regex...
 
@inspectorG4dget I believe there are some interpretations of regexes that don't follow the theoretical model. One can prove they are infact turing complete, which means they should be able to parse any of those things.
 
@AndrasDeak No, i dont think recursive regex qualifies.
 
Certainly there are plenty of regex engines that provide more bells and whistles than the theoretical bare essentials. The third party library regex has recursive regexes, for example, which means it can parse nested data. Unlike the built-in re.
 
2:12 PM
As far as im aware in any case, having an external loop and processing the same string over and over is considered above and beyond the scope of regex
 
@Kevin My point is, the bells and whistles aren't simple macros (so to speak) for making regexes more convenient, they literally make regexes not regexes.
 
Allowing parsing of arbitrarily nested expressions for starters.
 
Personal goal, The day , i understand what you guys talk in this room, that Day I will consider myself a good python programmer
 
@Anarach careful, the day you completely understand Kevin, the world will end. :)
 
@Dair Sure. I think even re has features that don't boil down to syntactic sugar. Negative lookahead, for example. But do keep in mind that "more powerful than ordinary regex" does not necessarily imply "can parse anything"
 
2:15 PM
@ParitoshSingh Lol..
 
Even with all the crazy things re supports, you still can't match "any number of Xes, followed by exactly that many Ys"
 
@Kevin In the see this link I linked to a brainf* interpreter in regex. It can most certainly parse 0^n1^n
But they also use perl's impl of regex
@Anarach Got to start hitting those intro theoretical CS books.
cbg
or wait, rbrb i forget which is which
 
rbrb Dair
random, curious. do you guys use any password managers?
 
Yeah, KeePass
 
2:21 PM
I've been using unix pass for a while, which is probably not exactly what you're asking
(it is a password manager, but quite on the luddite side)
 
ah i see. i had to google luddite :P
 
@Dair Oh, if you have an unlimited number of find/replaces, then yeah you can match "X"*n+"Y"*n.
 
Im thinking of taking the plunge, i got two notifications of login attempts to my account today
It's always been on the back of my mind, but i never tried a password manager before
 
I swear by password managers. Arguably makes you more vulnerable to certain kinds of attacks (ie - rubber hose analysis), but helps to protect against the more common kind of threat.
 
>>> "xxxxxyyyyy"
'xxxxxyyyyy'
>>> re.sub("$y.*^", "does not match", re.sub("$^", "matches", re.sub("xy", "", _)))
'xxxxyyyy'
>>> re.sub("$y.*^", "does not match", re.sub("$^", "matches", re.sub("xy", "", _)))
'xxxyyy'
>>> re.sub("$y.*^", "does not match", re.sub("$^", "matches", re.sub("xy", "", _)))
'xxyy'
>>> re.sub("$y.*^", "does not match", re.sub("$^", "matches", re.sub("xy", "", _)))
'xy'
>>> re.sub("$y.*^", "does not match", re.sub("$^", "matches", re.sub("xy", "", _)))
'matches'
 
2:25 PM
Stray thought of the day: aren't with statements against the zen of python?
 
Hm, curious, can you elaborate what issues you see* with it?
(note, there's probably some ways in which it would also be in sync with the zen as well)
 
Oops, I got the dollar sign and caret backwards in that code
 
"There should be one-- and preferably only one --obvious way to do it."
 
@Dair absolutely right. And regex /has/ been proven to be Turing Complete (citation required)
 
I'm surprised that both "$^" and "^$" match the empty string, but I guess it makes sense since they don't consume any characters
 
2:28 PM
@OldTinfoil that's like saying that reducing the chance of cardiac arrest makes you more susceptible to cancer
 
@AndrasDeak It's a fair comparison ^^
 
oh no, cancer! i better stick with cardiac arrest! :P
 
@OldTinfoil and why would they be? With statements are syntactical sugar that do cleanup with some error handling
 
@OldTinfoil I think the statement i "assume" you're counting as equivalent with an explicit close call, isn't actually equivalent.
Since there's no guaranteed cleanup without a context manager/finally block
Which makes "with" really the one obvious way to do it.
 
I'm skeptical whether a single regex call can be turing complete, even with recursive regex and whatever other cool features you'd care to use. The BF interpreter linked above requires an indefinite number of regex calls, so it doesn't satisfy me
 
2:31 PM
But wouldn't your usual try/catch/finally be one obvious way to do it?
 
@OldTinfoil it wouldn't be obvious because it's messy
similarly to how you don't use .append in a loop if you can use a single call to .extend
 
Fair point
 
or how you don't use foo = decorator(foo) but rather @decorator
 
I think there's a reason that the rule isn't worded "there should be only one obvious way to do it". The presence of "preferably" implies that sometimes you just have to accept that there's more than one obvious way.
Maybe the devs would have loved to make with open(...) as file: the one and only way to open files, but backwards compatibility demanded that they keep the other ways.
 
and sometimes you might want to pass contexts around
 
2:43 PM
Ordinary regexes can't run forever, right? It's easy enough to write a regex that takes a million billion years to complete, but that's not the same as infinity
I don't think you can be Turing-complete unless you can enter a loop that never completes
 
@OldTinfoil with statements exist for internal error handling, whereas try/except exists for external error handling. It's pretty similar to how we have both for and while -- and I'd rather give up while.
 
print(regex.match("(?R)", "foobar")) runs until it crashes with a MemoryError, so that kind of counts...
 
for that matter, I just read an article about how RLocks in general are not safe, because you can mess up unlocking -- something that is straight impossible in languages that allow them only in with like constructs.
 
Back - my 3D printer decided to press the renegade button
> "you just have to accept that there's more than one obvious way."

But isn't this the slippery slope that leaves us with PHP-like languages?
 
3:00 PM
there are a few very sore points like string formatting, otherwise there's often only one or two reasonable choice
 
On the topic of renegade machines with free will, I watched Ex Machina and I need someone to explain it to me.
 
might be a limited interpretation of course
and it's been a while since I saw it
 
@OldTinfoil cbg all, and let me jump in with 2 cents: The Zen of Python has been around a long time, and what was the obvious way to do things in Python 1.x may have been replaced with improved idioms in Python 2 or 3. That doesn't mean the new features are "against the Zen of Python", they just replace the former conventions. Prior to the introduction of "with" the only real way to guarantee cleanup with try-finally. Using "with" makes this code much cleaner, and so it's the preferred way now.
 
Not to mention, it's easy to quote specific lines of zen in both "for" and "against" many cases of syntax, ultimately it's important to treat it as guidelines too.
 
Ok, I think there's some merit to that explanation. view spoiler
 
3:07 PM
unfortunately I don't remember more details
 
can't comment on that :)
 
My ultimate takeaway of the film: view spoiler
 
@OldTinfoil in this regard, I'm more concerned about the async variants of everything. These things do literally the same, just in a different environment.
stack full coroutines (ála gevent, LUA, ...) would have been much more composable.
 
3:27 PM
@OldTinfoil It's a slope, yeah, but I don't think it's so slippery that it dooms us to an inevitable decline. If the heuristic that the devs use when adding new features is "don't add new obvious ways to do things, unless the feature is so good that it's worth it", then I think we can trust them to know when to stop
 
speaking of which, how's the asspression trial going for you, @Kevin?
 
(At some point I really need to get my head around the async stuff - I was really excited when it was introduced, but then didn't get around to actually using it)
 
I'd call it "situational"
and the tooling really isn't up to speed yet
 
3 hours ago, by Kevin
Hey now. I've had a 100% success rate for using the walrus operator in a useful manner since its introduction. All one times.
About what I expected: useful, but only in some fairly rare situations
 
one good usage since 3 hours, give or take, then... mumbles xkcd.com/605
might be worth it
 
3:30 PM
The feature will pay for itself in a couple thousand years!
 
3:46 PM
is there some canonical answer for "I keep overriding the same name in a loop and wonder why I only get the last result" stackoverflow.com/questions/58593728/…
 
I think the 90% case for := was when you have a cascade of elif's doing successive checks against re's, and if there is a match, work with it in the body of the elif without calling re.match a second time. There is actual merit to this usage in not duplicating processing, not just syntax sugar. := in list comps can always be equivalenced with an explicit loop.
 
Ah, so something like pastebin.com/hStKxD39? I see the appeal in not having an increasingly indented pyramid of if blocks
 
44
Q: Match groups in Python

CurdIs there a way in Python to access match groups without explicitly creating a match object (or another way to beautify the example below)? Here is an example to clarify my motivation for the question: Following Perl code if ($statement =~ /I love (\w+)/) { print "He loves $1\n"; } elsif ...

 
I still can't help but feel this is a problem of the re API, not the language itself
 
Yes, if they added this to re, then := might not have had as compelling a case
 
3:54 PM
Somewhere buried in the transcript there's a message I wrote saying "all I really need is a stateful object that lets me do if matcher.match(pattern, s): print(matcher.get_last_match().group())"
 
And also the shame of borrowing from Perl - <shudder>
 
morning cabbage
 
user11867329
4:12 PM
h
 
user11867329
Halp
 
user11867329
I have this:

csvfile:
id,wtv,wtv2,thing1,thing2,thing3,thing4,wtv3,thing5,wtv4

contentfile:
thing1
thing2
thing3
thing4
thing5
-
thing1(anotherproduct)
thing2(anoth...
 
user11867329
I need a simple way/script to fill the CSV from contentfile
 
user11867329
so like, maybe add variable 1 to 5 start of line of content file then repeat for all products
 
user11867329
and then magic python
 
user11867329
4:14 PM
no/ye?
 
Perhaps you could read contentfile into one big list of lines, then use sopython.com/canon/14/splitting-a-list-into-even-chunks to separate out the product groups
 
user11867329
4:37 PM
Wait, making gist
 
Oh, if there aren't exactly five lines per product every time, then it's not as easy
 
user11867329
I'll consolidate them wtv
 
user11867329
I can also ask someone to do tasks like that
 
user11867329
So you can also say: have monkey do X
 
user11867329
4:40 PM
So, ideally, put all on same line?
 
user11867329
one line per "element"
 
user11867329
*?
 
Instruct monkey to make the csv themselves, then you don't need to do anything ;-)
 
user11867329
Yeah, monkey's pretty cute.
 
user11867329
Wouldn't want to turn a upside-down frown back down
 
4:41 PM
But seriously. Dynamic product line count isn't so difficult to account for. If every product has exactly three paragraphs, you can still separate them out even if each paragraph has an unknown number of lines.
 
user11867329
Also, monkey doesnt know or understand csv
 
user11867329
They don't
 
user11867329
I was mostly wondering if there's a pre-established platform for these types of stuff
 
user11867329
That I could learn on-the-top
 
user11867329
I figured, can't I just
 
user11867329
4:43 PM
add

value1=element1
value2=...
...
*new product*
value1=element 1 of second product...
...
 
user11867329
then simple script
 
user11867329
to ask mr python to:
take value one, place there, value 2 place there....
value5 place there...

SKIP LINE IN CSV

take next value1... etc
 
Color perception question: How would I go about writing a function that takes a color as input and makes it noticeably darker? As in, just enough to be noticeable. I tried to convert the color to HSL and subtract 0.1 from the lightness value, but that affects light colors way more than dark colors
 
user11867329
Like, Place value 1 to 5 accordingly, when @ 5 > skip csv line, keep reading content and do the same
 
user11867329
I'm just wondering if it's possible cause I know I'll get stuck with script using the same first 5 elements on all lines
 
user11867329
4:46 PM
because all values will be name e.g. value1-5
 
user11867329
Cause I couldn't script a calculator
 
wim
@Kevin perfect use-case for a callable class
 
@OakDev Maybe you could do that if there were exactly five lines in each product, but there aren't. Intimus pacmaster s has five specifications and HSM SHREDSTAR S10 has twelve. It would be hard to loop over every product and only create five variables for the first case, and create twelve for the second.
@wim Yeah, if I want stateful callables in production-quality code, classes are my best bet
 
user11867329
What if I ask monkey to identify elements
 
user11867329
with value1="element1"
 
user11867329
4:53 PM
or value5="
e
l
emen
t5"
 
user11867329
Then just loop element placing?
 
Ehhh. I don't think that would help much.
 
user11867329
How come?
 
You're still going to have to write a parser either way
 
user11867329
Can't script do like
Place value1 here, value 2 there... value 5 here THEN skip line THEN loop
 
user11867329
4:57 PM
Because encoding? Why? (pretty noob, maybe don't waste time explaining... tbh)
 
using Git, is using release branches or Tags more common for marking releases?
 
I think what I would do is parse the textual data into a proper data structure whose information can more easily be accessed. pastebin.com/qDstZSRi is one possible way. It creates a product list containing objects whose name, description, etc can be retrieved with regular old string indexing
So products[2]["specs"]["Colour"] gives the color specification of the third product, for example.
 
05:00 - 17:0017:00 - 00:00

« first day (3299 days earlier)      last day (1633 days later) »