|
huhu posted:
You can store your filename in a variable. code:
|
# ? Feb 13, 2016 19:01 |
|
|
# ? May 9, 2024 03:13 |
|
I hate how R seemingly randomly allows you to drop quotes in some places. I also hate places in Python where you can turn something into a string without quotes, e.g. the old dict pattern quote:dict(becomes_a_string_key=variable,...)
|
# ? Feb 13, 2016 19:10 |
|
Don't be so sure. Just look up "bare words" for python. Doing this in Ruby is a bit easier since monkeypatching has better support. http://stackoverflow.com/questions/29492895/bare-words-new-keywords-in-python That said, don't ever actually do this. Supporting bare words is a fun exercise in metaprogramming, but a hideous attribute to pollute your runtime with.
|
# ? Feb 13, 2016 19:48 |
|
Cingulate posted:I also hate places in Python where you can turn something into a string without quotes, e.g. the old dict pattern That's not really special, you are just passing the keys to a function as kwargs in the same way kwargs are treated for every function in Python.
|
# ? Feb 13, 2016 19:53 |
|
Hegel posted:Don't be so sure. Just look up "bare words" for python. Doing this in Ruby is a bit easier since monkeypatching has better support. I find this deeply unsettling.
|
# ? Feb 13, 2016 19:53 |
|
OnceIWasAnOstrich posted:That's not really special, you are just passing the keys to a function as kwargs in the same way kwargs are treated for every function in Python.
|
# ? Feb 13, 2016 20:01 |
|
Cingulate posted:Good point, but they're turned into strings still! Yeah but I'm not really sure why it annoys you
|
# ? Feb 13, 2016 20:16 |
|
QuarkJets posted:Yeah but I'm not really sure why it annoys you
|
# ? Feb 13, 2016 20:21 |
|
As someone who is forced to work on projects in TCL at my job this conversation is triggering me.
|
# ? Feb 13, 2016 20:22 |
|
Cingulate posted:My feeble little mind has made a note that the relationship between the name of a variable referring to a string, and the string itself, is arbitrary. Here is an example where it's different. Maybe I'm misunderstanding, but I don't think that's the case; my_dict['some_variable'] doesn't return the string 'some_variable', unless you explicitly set that up. This might also blow your mind: every Python variable is also an entry in a dictionary, so technically every variable can also be accessed as a string. But again, the string keys in the dictionary don't refer to themselves
|
# ? Feb 13, 2016 20:32 |
|
Hegel posted:Don't be so sure. Just look up "bare words" for python. Doing this in Ruby is a bit easier since monkeypatching has better support. That looks quite fun as a novel way of adding support for some syntax you want for a task you often want to do at the repl.
|
# ? Feb 13, 2016 20:35 |
|
QuarkJets posted:Maybe I'm misunderstanding, but I don't think that's the case; my_dict['some_variable'] doesn't return the string 'some_variable', unless you explicitly set that up. QuarkJets posted:This might also blow your mind: every Python variable is also an entry in a dictionary, so technically every variable can also be accessed as a string. But again, the string keys in the dictionary don't refer to themselves
|
# ? Feb 13, 2016 20:37 |
|
Cingulate posted:Yeah, but accessing the globals dict is typically presented as bad behavior isn't it? Absolutely
|
# ? Feb 13, 2016 20:44 |
|
Cingulate posted:You're probably thinking too much about this ... I never claimed I have a rational argument against the syntax of dict(). One of the things people tried previously to point out is that this is not something special about the dict() builtin. This is something you can do in any function. So at the risk of being pedantic, referring to this as "the syntax of dict()" is not accurate. It's merely the way dict() treats its keyword arguments. code:
quote:Yeah, but accessing the globals dict is typically presented as bad behavior isn't it? The poster didn't mention the globals dict. The globals dict is not the only context in which one can access a dictionary with variables or object attributes as string keys. try this at the repl: code:
|
# ? Feb 13, 2016 20:48 |
|
Simplified question.code:
huhu fucked around with this message at 20:57 on Feb 13, 2016 |
# ? Feb 13, 2016 20:52 |
|
huhu posted:Simplified question. You could change the statement in method2() to Test.method() Better than that (but it is potentially difficult for a beginner to appreciate why), you can make method2 a class method: code:
Also, I haven't fixed this in my code but method() should either have a self parameter or be marked as a static method or class method (in the latter case it should have a cls parameter instead)
|
# ? Feb 13, 2016 21:05 |
|
Okay, I know this code is terrible in general, but there's things I might end up doing in the future with it, but I'm writing a simple ping script that will write to a text file to see if a list of computers is online. Here is what I have so far: The csv is just a list of computer names and people who "own' them (computer,owner). Python code:
e: one thing I'm coming up is I should be using subprocess.call instead of the way I'm doing it. e2: Seems subprocess.call does the same thing, I'm seeing a -c switch but I'm not sure how it works, guess it's time to learn ping more in depth! Gothmog1065 fucked around with this message at 22:27 on Feb 18, 2016 |
# ? Feb 18, 2016 22:18 |
|
Python comes with a csv module which will simplify some of that Your more general questions is that pinging by computer name will only work if you get name resolution via NetBIOS/WINS, which if you're in a domain should "just" work (or really I think even if you're just on the same subnet, I think Windows runs network discovery services for those kind of name announcements, though I can't remember for sure). The name resolution stuff is more of a network sys admin question. Hopefully they're aware of what you're doing if you're going to be randomly pinging machines on the network
|
# ? Feb 18, 2016 23:12 |
|
No Safe Word posted:Python comes with a csv module which will simplify some of that I'll definitely hit up my network guys to see the best way to check if a computer is online. It's definitely not going to be something run constantly or on a lot of computers (85 is the max right now, and 90% of them are in the same subnet). The DNS is doing something weird and losing the IPs for connected devices for some reason, it's weird, but it's probably something on the switch itself (since I don't think we're hitting the global DNS server, just what is stored on the switch for now). Either way, I'll see what my network guys come up with. Thanks!
|
# ? Feb 19, 2016 01:59 |
|
Gothmog1065 posted:Okay, I know this code is terrible in general, but there's things I might end up doing in the future with it, but I'm writing a simple ping script that will write to a text file to see if a list of computers is online. Here is what I have so far: While you're at it, I would look at async and await, because blocking on network calls is for chumps. Chumps!
|
# ? Feb 19, 2016 03:59 |
|
I'm working on a project that allows the creation of a number of different plots/running various analyses from the command line. Currently the output directory where the plots are saved is fixed relative to the project directory. I'd like to have it so that the user can specify an alternate location as a command line option if they want but otherwise it would default to whatever setting is in a configuration file. Eventually, many more options need to be configurable so the settings can be used throughout the program. I'm not really sure what the best way to go about implementing some sort of global configuration system is, though. Should I just read from the file into some object, override any settings that the user specifies on the command line and then pass the object around to any functions that need configuration? I'm just not sure how to design this in a way that won't make future development super cumbersome.
|
# ? Feb 21, 2016 05:48 |
|
code:
code:
code:
code:
|
# ? Feb 21, 2016 19:14 |
|
FEFF is a zero-width space. You've probably got one in your file.
|
# ? Feb 21, 2016 19:27 |
|
Asymmetrikon posted:FEFF is a zero-width space. You've probably got one in your file. I've found this: http://stackoverflow.com/questions/17912307/u-ufeff-in-python-string Is a zero-width space the fact that's encoded in UTF-8? And how would I go about removing that? I've tried reading the instructions listed on the page and I don't understand it at all.
|
# ? Feb 21, 2016 19:33 |
|
huhu posted:
code:
|
# ? Feb 21, 2016 19:45 |
|
Whoops, you're right, it's being used as a BOM. U+FEFF is for UTF-16, though; are you sure your file is UTF-8?
|
# ? Feb 21, 2016 19:54 |
|
Some tools on Windows (like Notepad, as I recall) prepend U+FEFF to files before saving as UTF-8. Though this doesn't function as a byte order mark (since the concept of byte order doesn't apply to UTF-8), it's still technically valid and serves as a marker that "this file is definitely UTF-8 content". Python defines a special codec called utf-8-sig that strips the leading UTF-8 "signature" from the beginning of the file. code:
|
# ? Feb 21, 2016 20:00 |
|
Speaking of string encoding, is there an elegant way to fix mangled ascii(?) charcters; ie something simpler and broader than this:Python code:
Python code:
Dominoes fucked around with this message at 00:08 on Feb 22, 2016 |
# ? Feb 21, 2016 21:53 |
|
I really don't understand the question
|
# ? Feb 22, 2016 02:26 |
|
https://github.com/kmike/text-unidecode/ or https://pypi.python.org/pypi/Unidecode
|
# ? Feb 22, 2016 02:56 |
|
Lysidas posted:Some tools on Windows (like Notepad, as I recall) prepend U+FEFF to files before saving as UTF-8. Though this doesn't function as a byte order mark (since the concept of byte order doesn't apply to UTF-8), it's still technically valid and serves as a marker that "this file is definitely UTF-8 content". I'm continually amazed how Windows manages to mangle files. We bought some Bing search ads and hooked up our normal analytics pipeline to their API to download some CSVs that say how the ads did. Care to guess how it broke?
|
# ? Feb 22, 2016 06:29 |
|
KernelSlanders posted:I'm continually amazed how Windows manages to mangle files. We bought some Bing search ads and hooked up our normal analytics pipeline to their API to download some CSVs that say how the ads did. Care to guess how it broke? Line endings?
|
# ? Feb 22, 2016 11:11 |
|
KernelSlanders posted:I'm continually amazed how Windows manages to mangle files. We bought some Bing search ads and hooked up our normal analytics pipeline to their API to download some CSVs that say how the ads did. Care to guess how it broke? Trick question. The API broke.
|
# ? Feb 22, 2016 13:32 |
|
qntm posted:Line endings? Yup. Even if you work at Microsoft, who sits down to write a web endpoint and thinks CR LF termination is a good idea?
|
# ? Feb 22, 2016 15:34 |
|
KernelSlanders posted:Yup. Even if you work at Microsoft, who sits down to write a web endpoint and thinks CR LF termination is a good idea? That's still better than what Excel on OSX does with csv, which is terminate with CR alone.
|
# ? Feb 22, 2016 16:33 |
|
Dominoes posted:Speaking of string encoding, is there an elegant way to fix mangled ascii(?) charcters; ie something simpler and broader than this: You want to decode HTML entities. http://stackoverflow.com/a/2087433
|
# ? Feb 22, 2016 17:13 |
|
Suspicious Dish posted:You want to decode HTML entities. http://stackoverflow.com/a/2087433 html.unescape(mangled) Dominoes fucked around with this message at 20:00 on Feb 22, 2016 |
# ? Feb 22, 2016 19:55 |
|
KernelSlanders posted:Yup. Even if you work at Microsoft, who sits down to write a web endpoint and thinks CR LF termination is a good idea? Wikipedia says... "Most textual Internet protocols (including HTTP, SMTP, FTP, IRC, and many others) mandate the use of ASCII CR+LF ('\r\n', 0x0D 0x0A) on the protocol level, but recommend that tolerant applications recognize lone LF ('\n', 0x0A) as well." I'm not sure whether you were downloading files rather than making web requests, but it seems to me that in that case Microsoft are quite entitled to send you CR+LF files, and if you don't account for that possibility then that's your bag.
|
# ? Feb 23, 2016 13:36 |
|
That's for the protocol, though, not for the body of the content. The body is a chunk of random binary data and is not line-delimited. Even if it's coincidentally also textual data, like CSV data.
|
# ? Feb 23, 2016 18:30 |
|
|
# ? May 9, 2024 03:13 |
|
Hammerite posted:Wikipedia says... "Most textual Internet protocols (including HTTP, SMTP, FTP, IRC, and many others) mandate the use of ASCII CR+LF ('\r\n', 0x0D 0x0A) on the protocol level, but recommend that tolerant applications recognize lone LF ('\n', 0x0A) as well." I'm not sure whether you were downloading files rather than making web requests, but it seems to me that in that case Microsoft are quite entitled to send you CR+LF files, and if you don't account for that possibility then that's your bag. Downloading files.
|
# ? Feb 25, 2016 14:45 |