« first day (2923 days earlier)      last day (2024 days later) » 

4:20 AM
Drunk cbg random question do you consider yourself a responsible adult asking turning 30 next month I can’t seem to comprehend the concept, off to oriburus I go
@AndrasDeak ;)
 
 
1 hour later…
5:32 AM
I know that CSV to mainly used to write to excel files, but can be used to (.txt, .php, ect). Is there any other way to write to a .txt or .php file without using CSV?
 
5:58 AM
@vash_the_stampede cannot parse your message. Also, I haven't been drunk, don't intend to, and I don't like the taste of alcohol
@johnsmith I don't know about php, but you don't need CSV to write a txt file. I'm not sure what you are asking really here. If you want to write to a file in a format where the data is arranged like in a table, then it's better to use CSV even if you can do it without because it can cater for things that could be tedious to implement yourself such as separators and/or quoting that need escaping. If there are no such possibilities, then there's no issue.
 
6:17 AM
@Jerry i guess what i'm asking is do you know of a better library or module then CSV or is CSV as good as it gets when it comes to writing to files
@Jerry and you don't need CSV to write to .txt files? What would you use instead?
 
with open("file.txt", w) as f:
    f.write("test")
and no, I'm still too much of a beginner to python to be able to start recommending libraries. I'm just assuming that CSV is a standard library (it's a common standard library across many languages I believe)
that w should be in quotes as well
 
@Jerry interesting, your a beginner at python? you have so many points what languages do you usually program in?
 
Tcl
and yea, started some weeks ago
I did sort of knew some basic things about python, but I didn't really invest time to learn about the language
until some weeks ago that is
half my points are from answers though lol, which are language agnostic most of the time
then about a quarter from and and the rest kinda all over the place
 
@Jerry oh nice i've heard of Tcl before but haven't looked into it (i'm mainly a web-page programmer) what do you use it for?
 
some simple file io scripts at work (well, not that much anymore since I changed departments), but I have written a few personal (unfinished) personal apps, and a discord bot which I'm still working on too when I get some time
unfinished mainly because I always want to add more but can't find the time xD
 
6:28 AM
Nice
you've created a bot before? i've always found those to be really cool because i have no idea where to even start XD.
 
well, not from scratch since my understanding of how servers and networking works is lacking, but I've taken the code that someone else wrote, tried understanding it and then improve it through a lot of testing and trial/error
right now my bot is fine I guess when it comes to connecting, reconnecting on disconnects, and stuff
I'm just adding more functionalities as and when I can
the original code wouldn't reconnect nor send a resume request to the server to catch missed messages in discord before
and I added it after some time, totalling a year I think? Was working on it on and off
 
@Jerry what are you going to use it for?
do you know if that's how facebook and other social media sites check for "harmful language"? I've thought that they used Python to find harmful language,but now I'm convinced that they just have a ton of bots and people monitoring those bots because python is a great lanuage and does ALOT but when it comes to large amounts of data to look though it can take some time.
 
the bot? right now um, there's a thing that does web scrapping on two websites, one for anime (with subscription options in the form of PMs), one for pokemon news, some discord stuff; logging messages (deletes/edits to messages and message stats), name changes, member joins/leaves/bans/kicks, retrieving a user profile detail (user id is a snowflake that includes the user creation date for example)
I'm not sure. I personally wouldn't add a language filter feature to my bot for the simple reason that it's natural language processing and that once people know about it, they will find creative ways around it, which means, it wouldn't change anything in the end
like nothing stops someone from doing ascii art of a bad word and a script will likely not be able to understand
 
that's true
how do you even program a bot, like what language do you use?
 
6:45 AM
Tcl
and it might be easier to show:
that's the bot: https://github.com/Unknown008/MarshtompBot
that's the library: https://github.com/Unknown008/discord.tcl
I run MarshtompBot.tcl and it uses the library to connect to the server, send the id token, etc
 
@Jerry ah thank you for the information
 
it basically communicates with the server via http requests
llike I would do http::geturl url and wait for a response
parse the response and send more requests
but that's not python syntax xD
 
@Jerry honestly for work i used to program in JavaScript, php, and a couple of other web-site and server languages, but i never knew how fun programming could be until i started programming in python
like JavaScript is really useful but can get really crazy really fast
 
yea, I would expect those for web designing, and yes, it's fun! I'm hoping to be able to use python with blender maybe, and unity
 
nice
 
6:54 AM
I had a javascript discord bot before, but it was a hassle to upkeep and node.js has to be installed/updated and I'm not that comfortable with javascript
once discord had an update which required me updating node.js, I dropped it and looked for a Tcl bot, the language I know and trust
 
How much do you know about scraping with python?
 
I don't remember trying to do it with python
I'd look for how to get a webpage, then use BeautifulSoup for parsing (I came across this one while answering regex questions)
That'd be the first step: stackoverflow.com/a/645318/1578604
 
review-pls suggested edit (I rejected, but not entirely sure that's the right thing to do) - stackoverflow.com/review/suggested-edits/21153780
 
7:09 AM
Changing the file path in the code sample is a small plus, but ruining the formatting of the 2nd half of the answer is a big minus, so that's an easy reject IMO
600 upvotes on a "How do I do X? Also, how do I do Y?" question. Bleh.
 
that's what I thought, not worth the effort on a highly viewed / upvoted answer.
@Aran-Fey early days... (2009)
 
7:30 AM
I know this is a bit off topic from the chat, but does anyone have experience with bounties?
 
@johnsmith see if this is helpful? stackoverflow.com/help/privileges/set-bounties
 
ok i don't have the points for it that's why i don't know how to use it XD
 
recbg
 
cbg antti
 
8:23 AM
@johnsmith if you have a specific question you're stuck with which is at least 48 hours old you can also ask for help here
 
8:40 AM
i have a file with content like this:
##
## hosts: Domains served by ejabberd.
## You can define one or several, for example:
## hosts:
## - "example.net"
## - "example.com"
## - "example.org"
##
hosts:
- "localhost"
- "domain1"

##
## route_subdomains: Delegate subdomains to other XMPP servers.
i need to add extra host under hosts section .i tried this:
with open('fle.yml', 'r+') as fd:
contents = fd.readlines()
for index, line in enumerate(contents):
if line.startswith("hosts"):
contents.insert(index + 1, ' - domain 3')
break
fd.seek(0)
fd.writelines(contents)
 
I think this question about argument unpacking ought to be reopened. zip(*args) is different from def zip(*args). Any opinions?
 
@AndrasDeak are you sure? i won't be breaking the rules?
 
but it dosent works
 
@johnsmith read the rules and make sure
 
@anekix Your file looks like YAML, so why don't you use a yaml library?
 
8:44 AM
stackoverflow.com/q/52359545/8417724 30 days old wasn't able to get an answer
 
@johnsmith you're not a native English speaker, are you?
 
@Aran-Fey i have to preserve commenst & spaces without changinng anything
but pymal or other libraries i tried removes comments
 
@AndrasDeak No, I am a native speaker? was it my spelling, grammar or word choice?
 
@anekix First google result: stackoverflow.com/questions/7255885/…
 
@johnsmith we'll scrap you if you keep confusing scrapping and scraping :P
 
8:48 AM
@Aran-Fey i tried ruamel.yaml library with this code:
import ruamel.yaml
yaml = ruamel.yaml.YAML() # defaults to round-trip if no parameters given
code = yaml.load(file('s.yml','r'))
print code
code['hosts'].extend(hosts)
# print code
import sys
yaml.dump(code, file('tt.yml','w'))
 
(so I guess spelling)
 
but it modifies hosts like this:
hosts:
- localhost
- domain1
- domain2
- domain3
see spaces are modifed before each host
 
@AndrasDeak oh no no, no English here XD sorry about that
 
@anekix Not sure what spaces you're referring to. That output looks correct to me
 
@Aran-Fey in my original file there is a two-level indentation for each host.but i when i pasted it here it is removing spaces
something like
hosts:
- "localhost"
- "domain1"
ok it againg removed spaces
 
8:53 AM
format it as code
 
hosts:
   - host1
   - host2
 
Anyway, I don't know why it does that, and I don't know yaml well enough to know if it matters either
 
like this
thats why i was lookign for a solution with python
 
@johnsmith I suggest correcting editing your question with the correct spelling
 
@AndrasDeak i just did
 
8:58 AM
ah, right
 
@AndrasDeak any other suggestions are welcome
 
That's the only obvious one I saw but I don't do web stuff so I didn't read very carefully
 
@AndrasDeak alright thank you
 
9:32 AM
@johnsmith if you do if value not in done: instead of if value != done:? Also done needs to be a list (square brackets instead of braces)
also my bad, I do tend to misspell scraping xD in my head I pronounce it scrap-ping while it should be scray-ping
 
@Jerry I've been waiting 30 days for that answer........
thank you so much
 
this has less to do with scraping and more with comparing string against list xD
no prob
 
the correct answer is still open if you would like to post the answer
"correct answer check"
 
honestly I'm a bit hesitant as to what to put in the answer since it feels so short lol, but sure, I'll try to whip something up
 
your choice
I do have one more question and it's less about the correct answer and more about suggestions to changes in the question to counter the down votes. this question was the straw that got me ban from asking questions (my bad) and i've tried to change it every way i could think of to make it a better question but have fallen short, does anyone have any changes? if you have the time. stackoverflow.com/q/52378807/8417724
questions age: 29 days
 
9:58 AM
I think your solution to the other question is fine; I'd probably do the same
a lot of users don't revisit a question after it gets edited, unfortunately
it can be on purpose, or not
 
that's what i was thinking
 
I'm personally guilty to forget a lot myself, so like I would dv a question for being unclear or not showing enough effort and then don't know/see when said question gets edited for the better and my dv remains there
 
maybe that should be a new function in stackoverflow
 
ah right, I also just remembered, python doesn't use the 'array' term by the way
 
does it use list?
 
10:03 AM
python uses list, tuples, sets, dicts and I might be forgetting something
I prefer using lists, it's just personal preference and maybe some bias from Tcl which also uses lists (Tcl uses lists, arrays and dicts)
but each type has their own purpose, like tuples are immutable (cannot be changed [easily I think?]) and sets only store unique elements
dicts are pretty straightforward in that they always come in key/value pairs with unique keys
 
i think most people use them all interchangeably
 
yea
it's because different languages use different terminologies I think
like php doesn't use the 'list' term iirc
 
@Jerry there are arrays, but lists are not arrays
bytearray, array.array (stdlib) and numpy.array (3rd party) are all arrays
Calling a list an array is not terminology; it's blatantly wrong
 
@AndrasDeak so what would a list be
 
all right, I'm probably a bit too biased towards Tcl where everything is a string xD but yea, I haven't come across arrays in python till now
thanks for telling me :)
 
10:14 AM
@johnsmith a list is a list
Read a python tutorial
 
what come on you can't use the word as a definition for the word
ok so an array is a "ordered collection" of items with an index and a list is a "collection of items" quora.com/What-is-the-difference-between-an-ARRAY-and-a-LIST
 
cbg
 
10:41 AM
cbg
 
@Jerry you're literally solving all of my questions problems :'D
 
lol I wanted to check out that other Q you had xD
 
the real M.V.P.
 
Hi guys, is there any software you know that has a variable name and it's corresponding value as input
Then it'll be used for a formula
But the catch is
The values can be played with using a slider (meaning you slide the bar to test different values) and see how the formula will change
Something like:
Inputs - Heat 0 (--||--------------------------) 10
Output - Happiness = 1/(Heat+1)
That can have around 10 variables as sliders and inputs?
 
11:02 AM
sorry, I don't understand
it might be because I don't know any software that has a variable name
 
Like: "Heat", "Flavor", "Texture", "Consistency"
For example
I am looking for one with a dynamic chart
Where you can slide each variable to test a range of values and see how the output behaves
 
ok, so you are looking for a software that has a dynamic chart?
 
Yes if you know any
 
excel? If you can put the formulae for the different inputs, then you only need to refresh a chart that you have created
 
I was hoping it updates as you slide the bar around though
 
11:10 AM
with all the excel macros out there, I wouldn't be surprised if there was some kind of object to implement a sliding rule
but yes, I guess it's not tailor made
 
Yeah perhaps i'll try to stick with VBA
Just got lazy :P
So hard to find tools around for free
>:D
 
or you create it yourself :x
well, it's the same either way, either create it python or excel or something else
 
Yea thing is I am pressed for time
But you're right
 
I know a bit about Tableau and Spotfire, but that's a bit more data representation kinda software
 
Yeah I get you it's an analytics tool
Oh well just gotta custom make everything I use then :/
Hope there was some open source software platform
Or something lol
 
11:17 AM
well I would have no idea. Maybe others have =/ everyone seems to be a bit away at the moment
 
Yea cool. Thanks lol
 
Hi ,
My html page have different sections and can I access each section using single route or do I need to write definition for each section and different routes.I am using FLASK
 
11:45 AM
@johnsmith a list is a list(). type([]) => list
It's right there in the name
But on a general note, arrays should be contiguous blocks of memory while lists are traditionally stuff like linked lists (python lists are more complicated)
@Pherdindy matplotlib has widgets but it's not pretty. I assume tkinter can also do this but I'm not touching that
 
@AndrasDeak Thanks well hello excel haha
 
12:08 PM
on the list/array topic for example in javascript, what they call an array can have varying element data types, and as such, is actually a list they are trying to call array, right?
I guess what I am trying to say is: what a group of people believe is an array, is not the same as what another group of people else may think an array is, if I am objective. One of the two groups of people may be wrong, but it's at the end of the day, simply using the same word to mean different things; whence my comment earlier about terminology.
it's kinda unfortunate it is how it is, and I don't intend to point fingers at who's right and who's wrong
 
inb4 AD: "javascript is wrong"
ah, he's offline =(
 
@Jerry This turn into something like whats the difference between a stool and a chair debate XD
 
@johnsmith oh, I have plenty of notes for a stool vs chair debate ;)
 
@Jerry XD
 
jpp
@Jerry, There is a right way, and it's what the docs say :). Of course, there are sometimes discrepancies. One of the most infamous ones being in NumPy: np.vectorize isn't vectorised.
 
12:49 PM
Hoping my internet doesn't die like last time cbg.
 
also I just checked the quora link you posted earlier @johnsmith, and I think the answer I like best there is by Joshua Gross
 
cbg, I have a panda's question. I am new to pandas and trying to do a small project for work before I run through a full tutorial for pandas. Im not sure what its called in pandas so I havent had good luck finding results in my searches. Dont want the code written by anymeans just what I need to search for to help me out.
An example of my data an needed out put can be seen here dpaste.com/3TJA925. I want to search for values in column 'H' that are in column 'C' then return the data from both rows on one row in like a new CSV.
 
1:11 PM
Values in H that are in any row of column C? Or the same row as H?
 
jpp
I can't see your image. For any row and perfect match, something like df['H'].isin(df['C'].unique()); for checking strings are within another string in the same row, list comprehension probably best: [i in j for i, j in zip(df['H'], df['C'])]
 
nvm, looking at dpaste
 
@jpp it vectorizes when it comes to semantics.
@jpp he doesn't want code, he wants pointers/concepts :P
 
jpp
@AndrasDeak, That's my point, semantics can/are misleading. In this case, I've lost count of the number of times I've seen people use np.vectorize in the belief it does something special.
@ZackTarr, For concepts, I suggest you look at pd.Series.isin, and possibly pd.DataFrame.apply. str.__contains__ is implemented in Python via in, an undocumented trick is to use this built-in rather than expensive row-wise loops via pd.DataFrame.apply.
 
\o cbg
 
1:20 PM
o/
 
@ZackTarr in order to get your desired results, you need to specify more rules. For example, these values are also in both C and H [1, 4, 7] but are not included in the output. That means that you only want things that pass. But then you assume that the first pass from the first file matches up with the first pass from the second file and so on. What if there are a mismatch in number of passes? In other words, there is nothing else that ties those rows together.
It is either the order in which they appear or you should be getting an outer join type thing
 
Hey any thought one how to make a json(I am new to the json module, noooob) file with a structure like this:
{
"int_2_colour": {
"0": "(0, 92, 0)",
"1": "(85, 139, 204)",
...
},
"colour_2_int": {
"(0, 92, 0)": 0,
"(85, 139, 204)": 1,
...
}
 
cbg, good morning y'all
 
I suggest you spend more time figuring out how they tie together and why others don't. At the moment it is too vague.
 
LOL, missed a curly brace.
Too late to edit.
 
1:38 PM
rbrb all!
 
@Mr.Zeus I'm sure you've tried something like:
a = ["int_to_color","0","1"]
b = ["(0,92,0)", "(85,139,204)"]

c = {k:v for k,v in zip(a[1:], b)}
d = {k:v for k,v in zip(a[:1], [c])}

print(d)
{'int_to_color': {'0': '(0,92,0)', '1': '(85,139,204)'}}
probably looking for something fancier I assume
 
@jpp and @piRSquared thank you both for responding! Looking into that stuff now. As for the pass cases like pi mentioned. I made bad data. I should not have used the 1-7 dummy data. You were correct in saying I only want the 'pass' values to pass. The rest is dummy data. I was just lazy and didnt fill it out with random stuff.
 
jpp
1:58 PM
 
I think they are different enough
 
2:26 PM
hi
 
hello @ex080
 
hello
 
whaddup cabbagers
 
jpp
@piRSquared, For my guide, which aspect makes it "different enough", index vs series i.e.to_series, > 0 vs <= 1hr, or something else?
It's always a tough one with data analysis questions, esp when OP has made no attempt, so it's not clear where precisely they are finding difficulty
 
shifting values from index to series and using timedeltas. So combo of those two. I'm making assumptions about searchers not being able to generalize
 
2:34 PM
I'm working with twitter, and I made the mistake of storing the whole tweepy object instead of just the tweets to my storage. So now I have a CSV with multiple tweet objects. Here is just one tweepy object pastebin.com/2QvCEREz. How would I go about loading this back into python and extracting only the text field from _json. I have tried eval().
 
jpp
@piRSquared, Fair enough, I'll comment as related (as they are, indeed, related)
 
import pandas as pd
import json
df = pd.read_csv('./../tweets_dfs/ActAccordingly.csv')

for r in df['tweets']:
    d = eval(r)
 
**Let's Golf**: Assume I have a function that divvies up integers into a smaller set of buckets. I want a dictionary where keys are the smaller set of buckets and the values are lists of integers that got transformed to the keys.

What is the most succinct way to rewrite this function and the transformation to the dictionary?
from collections import defaultdict

def f(x):
  if x > 5:
    if x % 2 == 1:
      return "cat"
    else:
      return "snake"
  else:
    if x % 2 == 0:
      return "dog"
    else:
      return "sausage"

d = defaultdict(list)
for i in range(12):
  d[f(i)].append(i)

dict(d)

# {'cat': [7, 9, 11],
#  'dog': [0, 2, 4],
#  'sausage': [1, 3, 5],
#  'snake': [6, 8, 10]}
This is the best I've got:
from itertools import groupby

def f(x):
  return "dog snake sausage cat".split()[(x>5)+x%2*2]

{k: [*v] for k, v in groupby(sorted(range(12), key=f), key=f)}
 
@ex080 I don't know what that is but eval makes me wince
 
yarp
 
2:45 PM
@AndrasDeak this exact problem stackoverflow.com/questions/34264427/…
 
oh, sorry, I missed your message between the eval one and your greeting
so what does d = eval(r) give you for a given r?
 
SyntaxError: invalid syntax because of the the inconsistent spacing
 
do you want the text key of the _json argument?
 
Yes
I think regex is the only sol.
 
or just manual parsing
@ex080 I'm pretty sure the invalid syntax comes from _api=<tweepy.api.API object at 0x7fea81934a90>
try replacing that with _api=... with a sane tweepy API object
 
2:54 PM
you're right.
 
can we loop this function before it goes to "Except'
def macGrabber(child,switch,cat = False):
try:
if cat is False:
child.expect('.#')
child.sendline('sh mac address-table | no-more')
else:
child.sendline('sh mac address-table dynamic | i Gi')
child.expect('.#', timeout=3000)
except pexpect.TIMEOUT:
print child.before,child.after
child.close()
raise
macs = child.before
child.close()
macs = macs.splitlines()
print('Connection to %s CLOSED' % switch)
return macs
 
in the one example of course; if it works we can figure out how to replace automatically (it won't be hard)
@Jinni please read sopython.com/wiki/… for formatting multiline code in chat
 
3:11 PM
Can I use a list comprehension to get a subsection of a list and also the section I didn't grab?
data = [1,2,3]
twos = [n for n in data if n ==2]
nottwo = ????
Without directly saying n != 2.. Instead just saying, get everything I didn't grab from the first filter.
 
@AndrasDeak I figured it would take a really long time to process 10,000,000 of these using regex or parsing. so I retarted the mining process. thanks for your help!
 
OK, it's your call:)
 
@Johnston Nope. A list comprehension creates one list, not two.
 
@Johnston [n for n in data if n < 2]
[n for n in data if n > 2]
 
What I'm looking for is to partition a list into true and false entries
 
3:20 PM
and you want to get these one at a time?
 
@johnsmith preferably.
 
r = [1,2,3]
e = [n for n in r if n == 2]
print(e)
[2]
t = [n for n in r if n not in e]
[1, 3]
i'm fixing it for one at a time
 
twos = []
nottwos = []
for n in data:
    if n == 2:
        twos.append(n)
    else:
        nottwos.append(n)
or: nottwos = [n for n in data if n != 2]; twos = [2]*(len(data) - len(nottwos)) :P
 
3:36 PM
t = [n for n in r if n not in e][1]
r = [1,2,3]
e = [n for n in r if n == 2]
 
t = [n for n in r if n not in e][1]
sorry about that
 
@AndrasDeak closed
 
thanks
 
Can anyone help explain/solve an issue I'm having with numpy.vectorize? I want to vectorize a function that takes two vectors (1d arrays) so that it can take a 3d array
 
3:46 PM
you're better off vectorizing yourself if that's possible
np.vectorize is just a wrapper for a loop
but anyway, go on
 
you're also better off using python 3 :)
 
im affraid im bound to python 2 :/
 
How so?
 
Project requirements
 
3:49 PM
that sounds awful
 
yup, anyways - the function I want to vectorize takes two state vectors (i and j) and does (will) do a vector calculation
 
What kind of vector calculation? I'm only asking because if you can vectorize yourself it will be much more efficient
 
its a custom Physics problem
 
I kind of figured that
if it's linear algebra you can almost certainly vectorize it
 
the two state vectors are used to calculate a matrix element
 
3:52 PM
if there are funny stuff like curve fitting or solving differential equations you almost certainly can't
 
and then from there i take a set of state vectors and produce a matrix from the various calculated elements
 
you'll probably be able to vectorize that
 
my plan was to take a matrix [[s1, s2, s3], [s1, s2, s3], [s1, s2, s3]]
and apply the function against its transpose
so that my function receives(state_i, state_j)
and then pass that onto numpy.from_function()
 
I think you could play around with the signature kwarg of np.vectorize, but it might not be possible to handle scalar and array input this differently
if you want 1darrays to be passed for the 3d case, you'll probably get 1d arrays passed for the 2d case
vectorize behaves such that additional dimensions are automatically handled, but the dimensions that the function receives are fixed, I think
 

« first day (2923 days earlier)      last day (2024 days later) »