python-2.7

How to execute a python script in a different directory?

懵懂的女人 提交于 2021-02-17 15:21:49
问题 Solved see my answer below for anyone who might find this helpful. I have two scripts a.py and b.py. In my current directory "C:\Users\MyName\Desktop\MAIN", I run > python a.py. The first script, a.py runs in my current directory, does something to a bunch of files and creates a new directory (testA) with the edited versions of those files which are simultaneously moved into that new directory. Then I need to run b.py for the files in testA. As a beginner, I would just copy and paste my b.py

How to convert a nested list into a one-dimensional list in Python?

二次信任 提交于 2021-02-17 13:00:26
问题 I tried everything (in my knowledge) from splitting the array and joining them up together and even using itertools: import itertools def oneDArray(x): return list(itertools.chain(*x)) The result I want: a) print oneDArray([1,[2,2,2],4]) == [1,2,2,2,4] Strangely, it works for b) print oneDArray([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == [1, 2, 3, 4, 5, 6, 7, 8, 9] Question 1) How do I get part a to work the way I want (any hints?) Question 2) Why does the following code above work for part b and

How can I align every word from this list?

|▌冷眼眸甩不掉的悲伤 提交于 2021-02-17 07:11:50
问题 I have a list of lists in a file: [ [ 'aaaaa', 'bbb','ccccccccc' ], [ 'aaaaa', 'bbbbbb','cccccc' ], [ 'aaa', 'bbb','ccccccccc' ] ] aaaaa bbb ccccccccc aaaaa bbbbbb cccccc aaa bbb ccccccccc I use it for some analysis but because of the lengths of the words, it is hard to read, I want to format it to look something like this: aaaaa bbb ccccccccc aaaaa bbbbbb cccccc aaa bbb ccccccccc Maybe with some generous spaces between columns. I guess I can use .format function but I tried and I found no

python add users input to an empty list using a for loop

回眸只為那壹抹淺笑 提交于 2021-02-17 07:10:12
问题 so I want to add users input to an empty list using this code no_of_num=int(input('enter the number of numbers you would like to add\n='))#this will store the number of numbers to be added list_of_num=[]#this list will store the number to be added for i in range(0,no_of_num):#we will ask them for the input num=int(input('enter the number\n=')) list_of_num.append(num)#this will keep adding the numbers to the list result=sum_of_num(num) but when I try running this code it just add the last

Listing all instance of a class

旧街凉风 提交于 2021-02-17 06:47:08
问题 I wrote a Python module, with several classes that inherit from a single class called MasterBlock . I want to import this module in a script, create several instances of these classes, and then get a list of all the existing instances of all the childrens of this MasterBlock class. I found some solutions with vars()['Blocks.MasterBlock'].__subclasses__() but as the instances I have are child of child of MasterBlock , it doesn't work. Here is some example code: Module: Class MasterBlock: def

Python pip installation on Mac is not working

拜拜、爱过 提交于 2021-02-17 06:26:31
问题 I have a Macbook Air and want to install pip. I have the updated python version. I follow all the instructions but I cannot install any packages. I have been researching for more than 1 hour and looking at many articles and questions but I cannot figure it out. This is what is displayed on my Terminal when I try to install pip, and then install a package called beautifulsoup: arnau@MacBook-Air-de-Arnau ~ % python --version Python 2.7.16 arnau@MacBook-Air-de-Arnau ~ % curl https://bootstrap

Python 2.7 64-bit erroneously refer to 32-bit (x86) for include files

半城伤御伤魂 提交于 2021-02-17 05:44:26
问题 I'm doing some legacy work with Python 2.7.18 in 64 bit. When PIP calling the compiler (VC for Python), it erroneously refer to 32-bit (x86) sources looking for include files, for example "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.0.2\include" . For 32-bit everything works all OK; for 64-bit the pre-compiled wheel file is an alternative that I prefer not to use for now. I'm wondering did I miss any setting pointing python and its compiler to 64-bit instead of x86? Or, at lease I want

Why I can't pip install nltk on mac os?

两盒软妹~` 提交于 2021-02-17 05:10:11
问题 I'm using mac os mojave, install python 2.7 and install pip using python get-pip.py , I already try those command to install pip : pip install --upgrade pip pip install nltk and try sudo python -m pip install --upgrade nltk But also result to same error like in this image Or here in text: error in nltk setup command: 'install_requires' must be a string or list of strings containing valid project/version requirement specifiers; Expected version spec in singledispatch; python_version < "3.4" at

How to use sockets in Python and subprocess?

最后都变了- 提交于 2021-02-17 03:55:05
问题 /* Hey, this script is purely for fun, not anything illegal, besides its easy to stop and detect. Further on if I were to use it for illegal activities, why would I post it here? */ My problem is that I am not able to execute cmd commands from the client. I am not sure why although I have a hint that it is to do with some kind of socket error. When I try to execute the command it just does nothing no matter how long I wait. It's nothing wrong with the client as I have tested it out with a

How to use sockets in Python and subprocess?

帅比萌擦擦* 提交于 2021-02-17 03:54:35
问题 /* Hey, this script is purely for fun, not anything illegal, besides its easy to stop and detect. Further on if I were to use it for illegal activities, why would I post it here? */ My problem is that I am not able to execute cmd commands from the client. I am not sure why although I have a hint that it is to do with some kind of socket error. When I try to execute the command it just does nothing no matter how long I wait. It's nothing wrong with the client as I have tested it out with a