sys

What does sys.stdin read?

你。 提交于 2019-12-17 18:59:17
问题 I get how to open files, and then use Python's pre built in functions with them. But how does sys.stdin work? for something in sys.stdin: some stuff here lines = sys.stdin.readlines() What's the difference between the above two different uses on sys.stdin? Where is it reading the information from? Is it via keyboard, or do we still have to provide a file? 回答1: So you have used Python's "pre built in functions", presumably like this: file_object = open('filename') for something in file_object:

Where is Python's sys.path initialized from?

 ̄綄美尐妖づ 提交于 2019-12-16 21:18:13
问题 Where is Python's sys.path initialized from? UPD : Python is adding some paths before refering to PYTHONPATH: >>> import sys >>> from pprint import pprint as p >>> p(sys.path) ['', 'C:\\Python25\\lib\\site-packages\\setuptools-0.6c9-py2.5.egg', 'C:\\Python25\\lib\\site-packages\\orbited-0.7.8-py2.5.egg', 'C:\\Python25\\lib\\site-packages\\morbid-0.8.6.1-py2.5.egg', 'C:\\Python25\\lib\\site-packages\\demjson-1.4-py2.5.egg', 'C:\\Python25\\lib\\site-packages\\stomper-0.2.2-py2.5.egg', 'C:\

Importing python libraries from Github

浪尽此生 提交于 2019-12-14 04:16:45
问题 I have written some libraries in Python for use in my project. I have stored them locally on my system and also remotely on Github. Now every time I write some code I use sys.path.append() in the beginning to help import my libraries from the directory in my system. I was wondering that if there is anyway to import these files directly from my Github repository The link to my repo is this - Quacpy 回答1: This feels a bit off the wall but might work for you (if any of your libraries depend on

taking multiline input with sys.stdin

↘锁芯ラ 提交于 2019-12-13 11:36:19
问题 I have the following function: def getInput(): # define buffer (list of lines) buffer = [] run = True while run: # loop through each line of user input, adding it to buffer for line in sys.stdin.readlines(): if line == 'quit\n': run = False else: buffer.append(line.replace('\n','')) # return list of lines return buffer which is called in my function takeCommands(), which is called to actually run my program. However, this doesn't do anything. I'm hoping to add each line to an array, and once

What is an alternative to including sys/times.h on windows?

↘锁芯ラ 提交于 2019-12-13 02:35:35
问题 Background I am trying to compile some code on windows that has previously been compiled on QNX. According to this SO Question and this SO Question, I can resolve this issue by simply removing the include statements for sys/times.h. When I remove the includes, I get a bunch of errors saying that variables have not been defined within the scope. I assume this is because I have removed the include call. Question What is an alternative to using sys/times.h in the code so I can use it on windows?

Login to a website using python

余生长醉 提交于 2019-12-12 21:56:13
问题 I am trying to login to this page using Python.Here is my code from urllib2 import urlopen from bs4 import BeautifulSoup import requests import sys URL= 'http://coe2.annauniv.edu/result/index.php' soup = BeautifulSoup(urlopen(URL)) for hit in soup.findAll(attrs={'class' : 's2'}): print hit.contents[0].strip() RegisterNumber = raw_input("enter the register number") DateofBirth = raw_input("enter the date of birth [DD-MM-YYYY]") login_input = raw_input("enter the what is()?") def main(): #

Is it possible to write to a python frame object as returned by sys._getframe() from python code running within the interpreter?

 ̄綄美尐妖づ 提交于 2019-12-12 08:18:39
问题 Apropos of This question, there is a bit of scaffolding within the interpreter to inspect frame objects, which can be retrieved by sys._getframe() . The frame objects appear to be read only, but I can't find anything obvious in the docs that explicitly states this. Can someone confirm whether these objects are writeable (in some way) or read only? import sys def foobar(): xx='foo' ff = sys._getframe() ff.f_locals['xx'] = 'bar' print xx if __name__ == '__main__': foobar() This prints out ' foo

TypeError: 'float' object has no attribute '__getitem__' in while statement

依然范特西╮ 提交于 2019-12-12 02:35:52
问题 I am getting TypeError: 'float' object has no attribute ' getitem ' for my while statement below. I am not sure what the problem is in this case. I am using sys in the code s1P = 4.51775*10.0**16.0 ii= 1 while s1P[ii-1] > 0.0 sys.stdout.write('\rstep={0}'.format(ii)) sys.stdout.flush() Rad = s1r[ii-1]+delrms1[ii-1]*delm Mas = s1m[ii-1]*[i] Pres = s1P[ii-1]+delPms1[ii-1]*delm lPres = np.log10(Pres) Temp = s1T[ii-1]+delTms1[ii-1]*delm lTemp = np.log10(Temp) Lum = s1L[ii-1]+deLms1[ii-1]*delm Rho

Loading a defaultdict in Hadoop using pickle and sys.stdin

别来无恙 提交于 2019-12-11 17:34:07
问题 I posted a similar question about an hour ago, but have since deleted it after realising I was asking the wrong question. I have the following pickled defaultdict : ccollections defaultdict p0 (c__builtin__ list p1 tp2 Rp3 V"I love that" p4 (lp5 S'05-Aug-13 10:17' p6 aS'05-Aug-13 10:17' When using Hadoop, the input is always read in using: for line in sys.stdin: I tried reading the pickled defaultdict using this: myDict = pickle.load(sys.stdin) for text, date in myDict.iteritems(): But to no

Terminology: Argv, Invoking a program

最后都变了- 提交于 2019-12-11 11:56:58
问题 Hy Python Community - This is a basic terminology question about Argv and "invoke" I'm new to python and programmring. I was reading about the argv function in the sys module on openbookproject.com: "The argv variable holds a list of strings read in from the command line when a Python script is run. These command line arguments can be used to pass information into a program at the same time it is invoked ." http://openbookproject.net/thinkcs/python/english2e/ch10.html It seems really clear