qid
int64
46k
74.7M
question
stringlengths
54
37.8k
date
stringlengths
10
10
metadata
listlengths
3
3
response_j
stringlengths
17
26k
response_k
stringlengths
26
26k
63,191,480
I wrote a small code with python. But this part of the code doesn't work when game focused on and it doesnt respond back. `pyautogui.moveRel(-2, 4)` Also this part works when my cursor appear in menu or etc. too. But when i switched into game (when my cursor disappear and crosshair appeared) it doesn't work (doesn't ...
2020/07/31
[ "https://Stackoverflow.com/questions/63191480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14027997/" ]
I tried this code below: `import win32con` `import win32api` `win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, int(10), int(10), 0, 0)` And it worked in game. I think it relative with win32con. Anyway i got it.
This is how PyAutoGui works: ``` 0,0 X increases --> +---------------------------+ | | Y increases | | | | 1920 x 1080 screen | | | | V | | | | +-------------------...
63,191,480
I wrote a small code with python. But this part of the code doesn't work when game focused on and it doesnt respond back. `pyautogui.moveRel(-2, 4)` Also this part works when my cursor appear in menu or etc. too. But when i switched into game (when my cursor disappear and crosshair appeared) it doesn't work (doesn't ...
2020/07/31
[ "https://Stackoverflow.com/questions/63191480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14027997/" ]
I was with the same problem in linux. For me it was wayland. After switching to X, it worked. In `/etc/gdm3/custom.conf` uncomment the line `#WaylandEnable=false`.
This is how PyAutoGui works: ``` 0,0 X increases --> +---------------------------+ | | Y increases | | | | 1920 x 1080 screen | | | | V | | | | +-------------------...
22,049,248
I would like to develop an app engine application that directly stream data into a BigQuery table. According to Google's documentation there is a simple way to stream data into bigquery: * <http://googlecloudplatform.blogspot.co.il/2013/09/google-bigquery-goes-real-time-with-streaming-inserts-time-based-queries-and-...
2014/02/26
[ "https://Stackoverflow.com/questions/22049248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2558486/" ]
Minimal working (as long as you fill in the right ids for your project) example: ``` import httplib2 from apiclient import discovery from oauth2client import appengine _SCOPE = 'https://www.googleapis.com/auth/bigquery' # Change the following 3 values: PROJECT_ID = 'your_project' DATASET_ID = 'your_dataset' TABLE_ID...
Here is a working code example from an appengine app that streams records to a BigQuery table. It is open source at code.google.com: <http://code.google.com/p/bigquery-e2e/source/browse/sensors/cloud/src/main.py#124> To find out where the bigquery object comes from, see <http://code.google.com/p/bigquery-e2e/source/b...
39,771,024
I made a module and moved it to `/root/Downloads/Python-3.5.2/Lib/site-packages`. When I run bash command `python3` in this folder to start the ide and import the module it works. However if I run `python3` in any other directory (e.g. `/root/Documents/Python`) it says ```none ImportError: No module named 'exampleMod...
2016/09/29
[ "https://Stackoverflow.com/questions/39771024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6726467/" ]
Instead of moving the module I would suggest you add the location of the module to the `PYTHONPATH` environment variable. If this is set then the python interpreter will know where to look for your module. e.g. on Linux ```sh export PYTHONPATH=$PYTHONPATH:<insert module location here> ```
**If you are a window user and you are getting import issues from site-packages then you can add the path of your site-packages to env variable** [![enter image description here](https://i.stack.imgur.com/fmK0h.png)](https://i.stack.imgur.com/fmK0h.png) C:\Users\hp\AppData\Local\Programs\Python\Python310\Lib\site-pac...
39,771,024
I made a module and moved it to `/root/Downloads/Python-3.5.2/Lib/site-packages`. When I run bash command `python3` in this folder to start the ide and import the module it works. However if I run `python3` in any other directory (e.g. `/root/Documents/Python`) it says ```none ImportError: No module named 'exampleMod...
2016/09/29
[ "https://Stackoverflow.com/questions/39771024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6726467/" ]
There is two ways to make python find your module: 1. add the path where you module reside in your `PYTHONPATH` as suggested by bmat 2. add the path where you module reside in your script like this: ```py import sys sys.path.insert(0, '/root/Downloads/Python-3.5.2/Lib/site-packages') ```
**If you are a window user and you are getting import issues from site-packages then you can add the path of your site-packages to env variable** [![enter image description here](https://i.stack.imgur.com/fmK0h.png)](https://i.stack.imgur.com/fmK0h.png) C:\Users\hp\AppData\Local\Programs\Python\Python310\Lib\site-pac...
8,121,886
I'm sure this has been answered somewhere, because it's a very basic question - I can not, however, for the life of me, find the answer on the web. I feel like a complete idiot, but I have to ask so, here goes: I'm writing a python code that will produce a list of all page addresses on a domain. This is done using sel...
2011/11/14
[ "https://Stackoverflow.com/questions/8121886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1020693/" ]
I'm familiar with python's api of selenium but you probably can receive link using `get_attribute(attributename)` method. So it should be something like: ``` linkstr = "" for link in Listlinker: linkstr = link.get_attribute("href") if linkstr in Domenesider: pass elif str(HovedDomene) in linkstr: Domen...
> > I've been checking up on your tip to not use time.sleep(10) as a page load wait. From reading different posts itseems to me that waiting for page loading is redundant with selenium 2. Se for example link The reason being that selenium 2 has a implicit wait for load function. Just thought I'd mention it to you, sin...
52,131,675
I have list of list of integers as shown below: ``` flst = [[19], [21, 31], [22], [23], [9, 25], [26], [27, 29], [28], [27, 29], [2, 8, 30], [21, 31], [5, 11, 32], [33]] ``` I want to get the list of integers in increasing order as shown below: ``` out = [19, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32,...
2018/09/01
[ "https://Stackoverflow.com/questions/52131675", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6017391/" ]
Sure, you can pass field names as arguments and use `[arg]` accessors as you already do with `[key]`: ```js function populateClinicRoomSelect(object, valueField, labelField) { var selectArray = []; var options = []; for(var key in object) { if(object.hasOwnProperty(key)) { options = { val...
You mean like this? ```js function populateClinicRoomSelect(object, value, label) { value = value || "id"; // defaults value to id label = label || "RoomName"; // defaults label to RoomName var selectArray = []; var options = []; for(var key in object) { if(object.hasOwnProperty(key))...
44,456,572
Am getting the following error - Missing required dependencies ['numpy'] Standalone and via Django, without Apache2 integration - the code work likes charm, however things start to fall when used with Apache2. It refuses to import pandas or numpy giving one error after another. I am using Apache2, libapache2-mod-wsgi-...
2017/06/09
[ "https://Stackoverflow.com/questions/44456572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1759084/" ]
In your class fields ``` private Handler progressHandler = new Handler(); private Runnable progressRunnable = new Runnable() { @Override public void run() { progressDialog.setProgress(progressValue); progressHandler.postDelayed(this, 1000); } }; ``` When the time ...
do something lik this ``` new Thread(new Runnable() { public void run() { while (prStatus < 100) { prStatus += 1; handler.post(new Runnable() { public void run() { pb_2.setProgress(prStatus); } ...
17,056,796
I'm trying to send an ascii command over tcp/ip but python (i think) add a header to he string. if I do a `s.send(bytes('RV\n ', 'ascii'))` I get an eRV rather than RV when I inspect the command going out. Any ideas? [Previous post](https://stackoverflow.com/questions/16968253/python-3-tcp-ip-ascii-command).
2013/06/12
[ "https://Stackoverflow.com/questions/17056796", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2460673/" ]
If you want to stay away from SQL you can try with [EntityFramework.Extended](http://weblogs.asp.net/pwelter34/archive/2011/11/29/entity-framework-batch-update-and-future-queries.aspx). Provides support for writing LINQ like batch delete/update queries. I only tried it once, it worked nice, but not sure if i would us...
There are two ways I can think of right off hand to achieve what you are seeking. 1) create a stored procedure and call it from your entity model. 2) Send the raw command text to the db, see this [microsoft article](http://msdn.microsoft.com/en-us/data/jj592907.aspx)
17,420,528
I am following the book "how to think like a computer scientist" to learn python and am having some problems understanding the classes and object chapter. An exercise there says to write a function named moveRect that takes a Rectangle and 2 parameters named dx& dy. It should change the location of the rectangle by ad...
2013/07/02
[ "https://Stackoverflow.com/questions/17420528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1297440/" ]
In your first example, you passed the *class* as an argument instead of the *instance* you created. Because there is no `self.x` in the class `Rectangle`, the error was raised. You could just put the function in the class: ``` class Rectangle: def __init__(self, x, y, width, height): self.x = x se...
Frob instances, not types. ``` moveRect(rect, dx, dy) ```
17,420,528
I am following the book "how to think like a computer scientist" to learn python and am having some problems understanding the classes and object chapter. An exercise there says to write a function named moveRect that takes a Rectangle and 2 parameters named dx& dy. It should change the location of the rectangle by ad...
2013/07/02
[ "https://Stackoverflow.com/questions/17420528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1297440/" ]
You must specify the members and methods you want to access and use in your class declaration. inside the class the Instance you are currently working on is refered to by the name `self` (see the link below!): ``` class Rectangle: def __init__(self): self.x = 0 self.y = 0 self.width = 50 ...
Frob instances, not types. ``` moveRect(rect, dx, dy) ```
17,420,528
I am following the book "how to think like a computer scientist" to learn python and am having some problems understanding the classes and object chapter. An exercise there says to write a function named moveRect that takes a Rectangle and 2 parameters named dx& dy. It should change the location of the rectangle by ad...
2013/07/02
[ "https://Stackoverflow.com/questions/17420528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1297440/" ]
In your first example, you passed the *class* as an argument instead of the *instance* you created. Because there is no `self.x` in the class `Rectangle`, the error was raised. You could just put the function in the class: ``` class Rectangle: def __init__(self, x, y, width, height): self.x = x se...
Without overly complicating things, all you need to make your code work is to change ``` moveRect(Rectangle,dx,dy) ``` to ``` moveRect(rect, float(dx), float(dy)) ``` (You need to make sure to convert each string from `raw_input` into a number. In `moveRect`, you add `Rectangle.x` to `dx`, these two values need ...
17,420,528
I am following the book "how to think like a computer scientist" to learn python and am having some problems understanding the classes and object chapter. An exercise there says to write a function named moveRect that takes a Rectangle and 2 parameters named dx& dy. It should change the location of the rectangle by ad...
2013/07/02
[ "https://Stackoverflow.com/questions/17420528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1297440/" ]
You must specify the members and methods you want to access and use in your class declaration. inside the class the Instance you are currently working on is refered to by the name `self` (see the link below!): ``` class Rectangle: def __init__(self): self.x = 0 self.y = 0 self.width = 50 ...
Without overly complicating things, all you need to make your code work is to change ``` moveRect(Rectangle,dx,dy) ``` to ``` moveRect(rect, float(dx), float(dy)) ``` (You need to make sure to convert each string from `raw_input` into a number. In `moveRect`, you add `Rectangle.x` to `dx`, these two values need ...
30,460,461
I have this in my project urlconf `photocheck.urls`: ``` urlpatterns = patterns('', url(r'^admin/docs/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^rest/', include('core.urls')), url(r'^shotmaker/', include('shotmaker.urls')), url(r'^report/', incl...
2015/05/26
[ "https://Stackoverflow.com/questions/30460461", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4057053/" ]
Use [`reverse_lazy()`](https://docs.djangoproject.com/en/stable/ref/urlresolvers/#reverse-lazy) instead of `reverse()`.
I got same error and solved but only `reverse_lazy()` is not enough, use `reverse_lazy()` like `reverse_lazy('app_name:url_name')`.
20,338,064
I am trying to execute a command on a file such as chmod in a python script. How can I get the file name from command line to the script? I want to execute the script like so ./addExecute.py blah Where blah is the name of some file. The code I have is this: ``` #!/usr/bin/python import sys import os file = sys.argv[1...
2013/12/02
[ "https://Stackoverflow.com/questions/20338064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3058993/" ]
``` os.system("chmod 700 file") ^^^^--- literal string, looking for a file named "file" ``` You probably want ``` os.system("chmod 700 " + file) ^^^^^^---concatenate your variable named "file" ```
It could be something like ``` os.system("chmod 700 %s" % file) ```
20,338,064
I am trying to execute a command on a file such as chmod in a python script. How can I get the file name from command line to the script? I want to execute the script like so ./addExecute.py blah Where blah is the name of some file. The code I have is this: ``` #!/usr/bin/python import sys import os file = sys.argv[1...
2013/12/02
[ "https://Stackoverflow.com/questions/20338064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3058993/" ]
It could be something like ``` os.system("chmod 700 %s" % file) ```
As pointed out by other answers, you need to place the value of the variable *file* instead. However, following the suggested standard, you should use format and state it like ``` os.system("chmod 700 {:s}".format(file)) ``` Using ``` os.system("chmod 700 %s" % file) ``` is discouraged, cf. also [Python string fo...
20,338,064
I am trying to execute a command on a file such as chmod in a python script. How can I get the file name from command line to the script? I want to execute the script like so ./addExecute.py blah Where blah is the name of some file. The code I have is this: ``` #!/usr/bin/python import sys import os file = sys.argv[1...
2013/12/02
[ "https://Stackoverflow.com/questions/20338064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3058993/" ]
``` os.system("chmod 700 file") ^^^^--- literal string, looking for a file named "file" ``` You probably want ``` os.system("chmod 700 " + file) ^^^^^^---concatenate your variable named "file" ```
``` os.system("chmod 700 file") ``` file is not replaced by its value. Try this : ``` os.system("chmod 700 " + file) ``` BTW, you should check if the script was executed with parameters (you could have an error such as "list index out of range")
20,338,064
I am trying to execute a command on a file such as chmod in a python script. How can I get the file name from command line to the script? I want to execute the script like so ./addExecute.py blah Where blah is the name of some file. The code I have is this: ``` #!/usr/bin/python import sys import os file = sys.argv[1...
2013/12/02
[ "https://Stackoverflow.com/questions/20338064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3058993/" ]
``` os.system("chmod 700 file") ``` file is not replaced by its value. Try this : ``` os.system("chmod 700 " + file) ``` BTW, you should check if the script was executed with parameters (you could have an error such as "list index out of range")
As pointed out by other answers, you need to place the value of the variable *file* instead. However, following the suggested standard, you should use format and state it like ``` os.system("chmod 700 {:s}".format(file)) ``` Using ``` os.system("chmod 700 %s" % file) ``` is discouraged, cf. also [Python string fo...
20,338,064
I am trying to execute a command on a file such as chmod in a python script. How can I get the file name from command line to the script? I want to execute the script like so ./addExecute.py blah Where blah is the name of some file. The code I have is this: ``` #!/usr/bin/python import sys import os file = sys.argv[1...
2013/12/02
[ "https://Stackoverflow.com/questions/20338064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3058993/" ]
``` os.system("chmod 700 file") ^^^^--- literal string, looking for a file named "file" ``` You probably want ``` os.system("chmod 700 " + file) ^^^^^^---concatenate your variable named "file" ```
As pointed out by other answers, you need to place the value of the variable *file* instead. However, following the suggested standard, you should use format and state it like ``` os.system("chmod 700 {:s}".format(file)) ``` Using ``` os.system("chmod 700 %s" % file) ``` is discouraged, cf. also [Python string fo...
69,963,185
I am trying to convert excel database into python. I have a trading data which I need to import into the system in xml format. my code is following: ``` df = pd.read_excel("C:/Users/junag/Documents/XML/Portfolio2.xlsx", sheet_name="Sheet1", dtype=object) root = ET.Element('trading-data') root.set('xmlns:xsi', 'http:/...
2021/11/14
[ "https://Stackoverflow.com/questions/69963185", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17410005/" ]
If you are creating a binding then the property must be notifiable, that is, have an associated signal and emit it when it changes: ```py class Manager(QObject): processResult = Signal(bool) df_changed = Signal() def __init__(self): QObject.__init__(self) self.ds = "loading .." @Slot(...
you should set Row value after setting property, like this: ``` tbModel.setRow(1, { param_name: "number of classes", value: backend.paramDs } ) ``` tbModel is id of your Table View's Model
39,533,766
I'm having a little problem with a modal in django. I have a link which calls an id and the id is a modal. However, the modal isn't opening. I'm pretty sure that this is happening because the link is inside a "automatic" form, but I'm new in django and python so I have no idea. The code is: ``` {% block body %} ...
2016/09/16
[ "https://Stackoverflow.com/questions/39533766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5516104/" ]
Change your `<a>` tag to the following: ``` <a class="btn btn-info btn-block btn-password" href="#" data-toggle="modal" data-target="#change-password">Alterar senha</a> ``` At least this is how I do it in my Django templates. As I think **@souldeux** was trying to say, you need to use the `data-target` attribute...
``` <a class="btn btn-info btn-block btn-password" href="#change-password" data-toggle="modal">Alterar senha</a> ``` You need a `data-target` attribute in addition to your `data-toggle`. <http://getbootstrap.com/javascript/#live-demo>
39,533,766
I'm having a little problem with a modal in django. I have a link which calls an id and the id is a modal. However, the modal isn't opening. I'm pretty sure that this is happening because the link is inside a "automatic" form, but I'm new in django and python so I have no idea. The code is: ``` {% block body %} ...
2016/09/16
[ "https://Stackoverflow.com/questions/39533766", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5516104/" ]
Change your `<a>` tag to the following: ``` <a class="btn btn-info btn-block btn-password" href="#" data-toggle="modal" data-target="#change-password">Alterar senha</a> ``` At least this is how I do it in my Django templates. As I think **@souldeux** was trying to say, you need to use the `data-target` attribute...
try changing the tag "a" to tag "button" in ``` <a class="btn btn-info btn-block btn-password" href="#change-password" data-toggle="modal">Alterar senha</a> ``` and hide to fade in ``` <div class="modal hide" id="change-password"> ```
6,403,757
I tried installing pycurl via pip. it didn't work and instead it gives me this error. ``` running install running build running build_py running build_ext building 'pycurl' extension gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch i386 -arc...
2011/06/19
[ "https://Stackoverflow.com/questions/6403757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/200412/" ]
I got it working using this ``` sudo env ARCHFLAGS="-arch x86_64" pip install pycurl ```
if you are on linux with apt-get: ``` lnx#> apt-get search pycurl ``` To install: ``` lnx#> sudo apt-get install python-pycurl ``` if on linux with yum: ``` lnx#> yum search pycurl I get this on my comp: python-pycurl.x86_64 : A Python interface to libcurl ``` To install i've did: `lnx#> sudo yum install ...
33,442,411
In one of our homework problems, we need to write a class in python called Gate which contains the drawing and function of many different gates in a circuit. It describes as follows: ``` in1 = Gate("input") out1 = Gate("output") not1 = Gate("not") ``` Here `in1`, `out1`, `not1` are all instances of this class. What...
2015/10/30
[ "https://Stackoverflow.com/questions/33442411", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5508199/" ]
Create a wrapper function around `fun` to select an element of the array. For example, the following will integrate the first element of the array. ``` from scipy.integrate import quad # The function you want to integrate def fun(x, a): return np.asarray([a * x, a * x * x]) # The wrapper function def wrapper(x, ...
Your function returns an array, `integrate.quad` needs a float to integrate. So you want to give it a function that returns one of the elements from your array instead of the function itself. You can do that via a quick `lambda`: ``` def integrate(a, index=0) return quad(lambda x,y: fun(x, y)[index], 0, 1, args=a...
38,668,389
Im in need of help outputting the json key with python. I tried to output the name "carl". Python code : ``` from json import loads import json,urllib2 class yomamma: def __init__(self): url = urlopen('http://localhost/name.php').read() name = loads(url) print "Hello" (name) ``` Php code (fo...
2016/07/29
[ "https://Stackoverflow.com/questions/38668389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6580871/" ]
I'll just assume the PHP code works correctly, I don't know PHP very well. On the client, I recommend using [`requests`](http://docs.python-requests.org/en/master/) (installable through `pip install requests`): ``` import requests r = requests.get('http://localhost/name.php') data = r.json() print data['person_one']...
try this: ``` import json person_data = json.loads(url) print "Hello {}".format(person_data["person_one"]) ```
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
Below is the code that worked for me: ``` import os, zipfile dir_name = 'C:\\SomeDirectory' extension = ".zip" os.chdir(dir_name) # change directory from working dir to dir with files for item in os.listdir(dir_name): # loop through items in dir if item.endswith(extension): # check for ".zip" extension ...
You need to construct a `ZipFile` object with the filename, and *then* extract it: ``` zipfile.ZipFile.extract(item) ``` is wrong. ``` zipfile.ZipFile(item).extractall() ``` will extract all files from the zip file with the name contained in `item`. I think you should more closely read the documentation...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
The accepted answer works great! Just to extend the idea to unzip all the files with .zip extension within all the sub-directories inside a directory the following code seems to work well: ``` import os import zipfile for path, dir_list, file_list in os.walk(dir_path): for file_name in file_list: if fil...
You need to construct a `ZipFile` object with the filename, and *then* extract it: ``` zipfile.ZipFile.extract(item) ``` is wrong. ``` zipfile.ZipFile(item).extractall() ``` will extract all files from the zip file with the name contained in `item`. I think you should more closely read the documentation...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
I think this is shorter and worked fine for me. First import the modules required: ``` import zipfile, os ``` Then, I define the working directory: ``` working_directory = 'my_directory' os.chdir(working_directory) ``` After that you can use a combination of the `os` and `zipfile` to get where you want: ``` for ...
You need to construct a `ZipFile` object with the filename, and *then* extract it: ``` zipfile.ZipFile.extract(item) ``` is wrong. ``` zipfile.ZipFile(item).extractall() ``` will extract all files from the zip file with the name contained in `item`. I think you should more closely read the documentation...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
Below is the code that worked for me: ``` import os, zipfile dir_name = 'C:\\SomeDirectory' extension = ".zip" os.chdir(dir_name) # change directory from working dir to dir with files for item in os.listdir(dir_name): # loop through items in dir if item.endswith(extension): # check for ".zip" extension ...
The accepted answer works great! Just to extend the idea to unzip all the files with .zip extension within all the sub-directories inside a directory the following code seems to work well: ``` import os import zipfile for path, dir_list, file_list in os.walk(dir_path): for file_name in file_list: if fil...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
Below is the code that worked for me: ``` import os, zipfile dir_name = 'C:\\SomeDirectory' extension = ".zip" os.chdir(dir_name) # change directory from working dir to dir with files for item in os.listdir(dir_name): # loop through items in dir if item.endswith(extension): # check for ".zip" extension ...
I think this is shorter and worked fine for me. First import the modules required: ``` import zipfile, os ``` Then, I define the working directory: ``` working_directory = 'my_directory' os.chdir(working_directory) ``` After that you can use a combination of the `os` and `zipfile` to get where you want: ``` for ...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
Below is the code that worked for me: ``` import os, zipfile dir_name = 'C:\\SomeDirectory' extension = ".zip" os.chdir(dir_name) # change directory from working dir to dir with files for item in os.listdir(dir_name): # loop through items in dir if item.endswith(extension): # check for ".zip" extension ...
**Recursive** version of [@tpdance answer](https://stackoverflow.com/a/31355555/3030195). Use this for for **subfolders** and subfolder. Working on Python 3.8 ``` import os import zipfile base_dir = '/Users/john/data' # absolute path to the data folder extension = ".zip" os.chdir(base_dir) # change directory from ...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
I think this is shorter and worked fine for me. First import the modules required: ``` import zipfile, os ``` Then, I define the working directory: ``` working_directory = 'my_directory' os.chdir(working_directory) ``` After that you can use a combination of the `os` and `zipfile` to get where you want: ``` for ...
The accepted answer works great! Just to extend the idea to unzip all the files with .zip extension within all the sub-directories inside a directory the following code seems to work well: ``` import os import zipfile for path, dir_list, file_list in os.walk(dir_path): for file_name in file_list: if fil...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
The accepted answer works great! Just to extend the idea to unzip all the files with .zip extension within all the sub-directories inside a directory the following code seems to work well: ``` import os import zipfile for path, dir_list, file_list in os.walk(dir_path): for file_name in file_list: if fil...
**Recursive** version of [@tpdance answer](https://stackoverflow.com/a/31355555/3030195). Use this for for **subfolders** and subfolder. Working on Python 3.8 ``` import os import zipfile base_dir = '/Users/john/data' # absolute path to the data folder extension = ".zip" os.chdir(base_dir) # change directory from ...
31,346,790
I would like to write a simple script to iterate through all the files in a folder and unzip those that are zipped (.zip) to that same folder. For this project, I have a folder with nearly 100 zipped .las files and I'm hoping for an easy way to batch unzip them. I tried with following script ``` import os, zipfile fo...
2015/07/10
[ "https://Stackoverflow.com/questions/31346790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4688131/" ]
I think this is shorter and worked fine for me. First import the modules required: ``` import zipfile, os ``` Then, I define the working directory: ``` working_directory = 'my_directory' os.chdir(working_directory) ``` After that you can use a combination of the `os` and `zipfile` to get where you want: ``` for ...
**Recursive** version of [@tpdance answer](https://stackoverflow.com/a/31355555/3030195). Use this for for **subfolders** and subfolder. Working on Python 3.8 ``` import os import zipfile base_dir = '/Users/john/data' # absolute path to the data folder extension = ".zip" os.chdir(base_dir) # change directory from ...
55,355,567
I am writing code to read data from a CSV file to a pandas dataframe and to get the unique values and concatenate them as a string. The problem is that one of the columns contains the values `True` and `False`. So while concatenating the values I am getting the error > > > ``` > sequence item 0: expected str insta...
2019/03/26
[ "https://Stackoverflow.com/questions/55355567", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3584680/" ]
Python 3 does not preform implicit casts. You will need to explicitly cast your booleans to strings. This can be done easily with [`map` builtin function](https://docs.python.org/3/library/functions.html?highlight=builtin%20filter#map) which applies a function on each item of an iterable and returns the result: ``` s...
Use `.astype(str)` **Ex:** ``` df[i].unique().astype(str).tolist() ```
54,880,349
I have installed Python 3.7 64-bit on my 64-bit OS. I have also Installed mysql-installer-community-8.0.15.0 plus I installed MySQL connector using this code `python -m pip install mysql-connector` and still when I try to import mysql.connector. I get this error. > > "C:\Users\Basir > Payenda\PycharmProjects\newprj\...
2019/02/26
[ "https://Stackoverflow.com/questions/54880349", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11080590/" ]
You are doing ``` throw new InvalidTestScore("Invalid Test Score"); ``` so you have to declare that your method is actually going to throw this exception ``` public static void inTestScore(int[] arr) throws InvalidTestScore ```
You must declare that your method may throw this exception: ``` public static void inTestScore(int[] arr) throws InvalidTestScore { ... } ``` This allows the compiler to force any method that calls your method to either catch this exception, or declare that it may throw it.
63,710,044
I am trying to use Serverless Framework to deploy a Python Fast API WebApp. Is is related to issue: <https://github.com/jordaneremieff/mangum/issues/126> When I deploy it using serverless, sls depoy and Invoke the function I am getting the following error: ``` [ERROR] KeyError: 'requestContext' Traceback (most recen...
2020/09/02
[ "https://Stackoverflow.com/questions/63710044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1694699/" ]
The issue lies within the `mangum` adapter expecting input similar to the `event` content specified by [AWS API Gateway shown here](https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html). You'll see that there's a `requestResponse` dictionary there that the Mangum adapter seems to strictly require to fu...
You need to provide at least the **minimal** `Event data`, like in the example below, when you invoke a FastAPI-based lambda function (for example via AWS console Lambda -> Test Event): ``` { "resource": "/", "path": "/api/v1/test/", "httpMethod": "GET", "requestContext": { }, "multiValueQueryStringParamet...
24,478,623
I trying to setup virtualenvwrapper in GitBash (Windows 7). I write the next lines: `1 $ export WORKON_HOME=$HOME/.virtualenvs 2 $ export MSYS_HOME=/c/msys/1.0 3 $ source /usr/local/bin/virtualenvwrapper.sh` And the last line give me an error: `source /usr/local/bin/virtualenvwrapper.sh sh.exe: /usr/local/bin/virtu...
2014/06/29
[ "https://Stackoverflow.com/questions/24478623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I believe it has something to do with the "image" input. have you considered using a button element instead? ``` <button type="submit" name="someName" value="someValue"><img src="someImage.png" alt="SomeAlternateText"></button> ```
Try this :- ``` <form action="dologin.php" method="post"> <input type="text" name="email" class="form-control" placeholder="Username"> <input type="password" name="password" class="form-control" placeholder="Password"> <input type="image" src="img/login.png" type="submit" alt="Login"> </form> ``` And in dologi...
38,316,477
so i'm trying to convert a bash script, that i wrote, into python, that i'm learning, and the python equivalent of the bash whois just can't give me the answer that i need. this is what i have in bash- ``` whois 'ip address' | grep -i abuse | \ grep -o [[:alnum:]]*\@[[:alnum:]]*\.[[:alpha:]]* | sort -u ``` and...
2016/07/11
[ "https://Stackoverflow.com/questions/38316477", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6576450/" ]
This should do what you are looking for. It works correctly in the snippet. ```js window.onload = onPageLoad(); function onPageLoad() { document.getElementById("1403317").checked = true; } ``` ```html <input type="checkbox" id="1403317"> ```
try this one maybe ? ``` $(document).ready(function() { $('#1403317').attr('checked', true) }; ```
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
If you highlight some code, you can right-click or run the command, `Run Selection/Line in Python Terminal`. We are also planning on [implementing Ctrl-Enter](https://github.com/Microsoft/vscode-python/issues/1349) to do the same thing and looking at [Ctr-Enter executing the current line](https://github.com/Microsoft/...
One way you can do it is through the Integrated Terminal. Here is the guide to open/use it: <https://code.visualstudio.com/docs/editor/integrated-terminal> After that, type `python3` or `python` since it is depending on what version you are using. Then, copy and paste the fraction of code you want to run into the term...
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
In my ver of VSCode (1.25), shift+enter will run selection. Note that you will want to have your integrated terminal running python.
One way you can do it is through the Integrated Terminal. Here is the guide to open/use it: <https://code.visualstudio.com/docs/editor/integrated-terminal> After that, type `python3` or `python` since it is depending on what version you are using. Then, copy and paste the fraction of code you want to run into the term...
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
You can: 1. open a terminal at *Terminal>New Terminal* 2. Highlight the code you want to run 3. Hit *Terminal>Run Selected Text* As for R you can hit `CTRL Enter` to execute the highlighted code. For python there's apparently no default shortcut (see below), but I am quite sure you can add yours. [![enter image desc...
One way you can do it is through the Integrated Terminal. Here is the guide to open/use it: <https://code.visualstudio.com/docs/editor/integrated-terminal> After that, type `python3` or `python` since it is depending on what version you are using. Then, copy and paste the fraction of code you want to run into the term...
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
If you highlight some code, you can right-click or run the command, `Run Selection/Line in Python Terminal`. We are also planning on [implementing Ctrl-Enter](https://github.com/Microsoft/vscode-python/issues/1349) to do the same thing and looking at [Ctr-Enter executing the current line](https://github.com/Microsoft/...
In my ver of VSCode (1.25), shift+enter will run selection. Note that you will want to have your integrated terminal running python.
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
If you highlight some code, you can right-click or run the command, `Run Selection/Line in Python Terminal`. We are also planning on [implementing Ctrl-Enter](https://github.com/Microsoft/vscode-python/issues/1349) to do the same thing and looking at [Ctr-Enter executing the current line](https://github.com/Microsoft/...
I'm still trying to figure out how to make vscode do what I need (interactive python plots), but I can offer a more complete answer to the question at hand than what has been given so far: 1- Evaluate current selection in debug terminal is an option that is not enabled by default, so you may want to bind the 'editor.d...
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
You can: 1. open a terminal at *Terminal>New Terminal* 2. Highlight the code you want to run 3. Hit *Terminal>Run Selected Text* As for R you can hit `CTRL Enter` to execute the highlighted code. For python there's apparently no default shortcut (see below), but I am quite sure you can add yours. [![enter image desc...
In my ver of VSCode (1.25), shift+enter will run selection. Note that you will want to have your integrated terminal running python.
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
In my ver of VSCode (1.25), shift+enter will run selection. Note that you will want to have your integrated terminal running python.
I'm still trying to figure out how to make vscode do what I need (interactive python plots), but I can offer a more complete answer to the question at hand than what has been given so far: 1- Evaluate current selection in debug terminal is an option that is not enabled by default, so you may want to bind the 'editor.d...
49,771,589
I just made the transition from Spyder to VScode for my python endeavours. Is there a way to run individual lines of code? That's how I used to do my on-the-spot debugging, but I can't find an option for it in VScode and really don't want to keep setting and removing breakpoints. Thanks.
2018/04/11
[ "https://Stackoverflow.com/questions/49771589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4482349/" ]
You can: 1. open a terminal at *Terminal>New Terminal* 2. Highlight the code you want to run 3. Hit *Terminal>Run Selected Text* As for R you can hit `CTRL Enter` to execute the highlighted code. For python there's apparently no default shortcut (see below), but I am quite sure you can add yours. [![enter image desc...
I'm still trying to figure out how to make vscode do what I need (interactive python plots), but I can offer a more complete answer to the question at hand than what has been given so far: 1- Evaluate current selection in debug terminal is an option that is not enabled by default, so you may want to bind the 'editor.d...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
This also works well: ``` const fs = require('fs'); process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.replace(/\s*$/, '') ...
First, install prompt-sync: `npm i prompt-sync` Then in your JavaScript file: ``` const ps = require("prompt-sync"); const prompt = ps(); let name = prompt("What is your name? "); console.log("Hello, ", name); ``` That's it. You can improve this by adding `{sigint: true}` when initialising ps. With this configurat...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
The other solutions here are either async, or use the blocking `prompt-sync`. I want a blocking solution, but `prompt-sync` consistently corrupts my terminal. I found [a lovely answer here](https://github.com/nodejs/node/issues/28243) which offers a good solution. Create the function: ```js const prompt = msg => { ...
This also works well: ``` const fs = require('fs'); process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.replace(/\s*$/, '') ...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
This can also be done **natively with promises**. It is also more secure then using outside world NPM modules. No longer need to use callback syntax. Updated answer from @Willian. This will work with async/await syntax and es6/7. ```js const readline = require('readline'); const rl = readline.createInterface({ input...
This also works well: ``` const fs = require('fs'); process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.replace(/\s*$/, '') ...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
There are 3 options you could use. I will walk you through these examples: (Option 1) **prompt-sync:** In my opinion, it is the simpler one. It is a module available on npm and you can refer to the docs for more examples [prompt-sync](https://github.com/heapwolf/prompt-sync). ```sh npm install prompt-sync ``` ```js...
We can use the built-in readline module which is a wrapper around Standard I/O, suitable for taking user input from command line(terminal). Here's a simple example. Try the following in a new file: ``` const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: pr...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
The other solutions here are either async, or use the blocking `prompt-sync`. I want a blocking solution, but `prompt-sync` consistently corrupts my terminal. I found [a lovely answer here](https://github.com/nodejs/node/issues/28243) which offers a good solution. Create the function: ```js const prompt = msg => { ...
First, install prompt-sync: `npm i prompt-sync` Then in your JavaScript file: ``` const ps = require("prompt-sync"); const prompt = ps(); let name = prompt("What is your name? "); console.log("Hello, ", name); ``` That's it. You can improve this by adding `{sigint: true}` when initialising ps. With this configurat...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
This also works well: ``` const fs = require('fs'); process.stdin.resume(); process.stdin.setEncoding('utf-8'); let inputString = ''; let currentLine = 0; process.stdin.on('data', inputStdin => { inputString += inputStdin; }); process.stdin.on('end', _ => { inputString = inputString.replace(/\s*$/, '') ...
prompt package dont work properly in 'windows' environment. instead 'inquirer' package is better
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
This can also be done **natively with promises**. It is also more secure then using outside world NPM modules. No longer need to use callback syntax. Updated answer from @Willian. This will work with async/await syntax and es6/7. ```js const readline = require('readline'); const rl = readline.createInterface({ input...
First, install prompt-sync: `npm i prompt-sync` Then in your JavaScript file: ``` const ps = require("prompt-sync"); const prompt = ps(); let name = prompt("What is your name? "); console.log("Hello, ", name); ``` That's it. You can improve this by adding `{sigint: true}` when initialising ps. With this configurat...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
This can also be done **natively with promises**. It is also more secure then using outside world NPM modules. No longer need to use callback syntax. Updated answer from @Willian. This will work with async/await syntax and es6/7. ```js const readline = require('readline'); const rl = readline.createInterface({ input...
prompt package dont work properly in 'windows' environment. instead 'inquirer' package is better
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
This can also be done **natively with promises**. It is also more secure then using outside world NPM modules. No longer need to use callback syntax. Updated answer from @Willian. This will work with async/await syntax and es6/7. ```js const readline = require('readline'); const rl = readline.createInterface({ input...
If you want to use ESM (`import` instead of `require`): ``` import * as readline from 'node:readline/promises'; // This uses the promise-based APIs import { stdin as input, stdout as output } from 'node:process'; const rl = readline.createInterface({ input, output }); const answer = await rl.question('What do you t...
61,394,928
I have just started using Node.js, and I don't know how to get user input. I am looking for the JavaScript counterpart of the python function `input()` or the C function `gets`. Thanks.
2020/04/23
[ "https://Stackoverflow.com/questions/61394928", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13262787/" ]
Use this: ```js let inpt = Object.values(process.argv).slice(2).join(' ').toString(); ``` While running the file, you can provide inputs. Example: ``` node <file_name>.js <this_is_a_input> ```
We can use the built-in readline module which is a wrapper around Standard I/O, suitable for taking user input from command line(terminal). Here's a simple example. Try the following in a new file: ``` const readline = require("readline"); const rl = readline.createInterface({ input: process.stdin, output: pr...
46,776,264
My application requirement is to use our LDAP directory to authenticate a User based on their network login. I setup the LDAP correctly using ldap3 in my system.py. I'm able to bind to a user and identify credentials in python, not using Django. Which authentication backend would I set Django up to use to make my login...
2017/10/16
[ "https://Stackoverflow.com/questions/46776264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8570299/" ]
This is a broad question and I am not sure your experience with Django so without more information I would suggest trying [this](https://github.com/etianen/django-python3-ldap) or [this](http://fle.github.io/combine-ldap-and-classical-authentication-in-django.html)
I am running Python 3 and have used the excellent `django-python3-ldap` package with both OpenLDAP and Active Directory from Django 1.6 through 2.0. You can find it here: <https://github.com/etianen/django-python3-ldap> It is a well maintained package that we've been able to use as we upgrade Django from version to v...
49,352,889
I installed `fiona` as follows: ``` conda install -c conda-forge fiona ``` It installed without any errors. When I try to import `fiona`, I get the following error: Traceback (most recent call last): ``` File "<stdin>", line 1, in <module> File "/home/name/anaconda3/lib/python3.6/site-packages/fiona/__init__.p...
2018/03/18
[ "https://Stackoverflow.com/questions/49352889", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9400561/" ]
I guess this problem comes from conflicts with stuff already installed in the Anaconda distribution. My inelegant workaround is: ``` conda install -c conda-forge geopandas conda remove geopandas fiona pip install geopandas fiona ```
Because I did not want to uninstall geopandas, I solved the issue by upgrading fiona via pip ``` pip install --upgrade fiona ```
56,378,783
I'm doing a supposedly simple python challenge a friend gave me involving an elevator and the logic behind its movements. Everything was going well and good until I got to the point where I had to write how to determine if the elevator could move hit a called floor en route to its next queued floor. ```py def floorCom...
2019/05/30
[ "https://Stackoverflow.com/questions/56378783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10760049/" ]
I think your problem lies in the use of a for loop in conjunction with the queue.remove() function. It seems like the `for x in queue:` operator runs into problems when you edit the list while it runs. I would recommend using `while queue:` instead and setting x to the first element. ``` while queue: x = ...
The reason for it to skip floor 6, is because of removing the data from the list, which is being iterated. ``` l=[3,6,9,10,14] for i in l: print(i) ``` Output: 3 6 9 10 14 ``` for i in l: print(i) l.remove(i) ``` output: 3 9 14
56,378,783
I'm doing a supposedly simple python challenge a friend gave me involving an elevator and the logic behind its movements. Everything was going well and good until I got to the point where I had to write how to determine if the elevator could move hit a called floor en route to its next queued floor. ```py def floorCom...
2019/05/30
[ "https://Stackoverflow.com/questions/56378783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10760049/" ]
The reason for the early exit is because you are modifying the list while looping on it. To have a simple example: ``` l = [3,6,9,10] for x in l: print(x) l.remove(x) ``` The output is ``` 3 9 ``` However, there are many other problems with your current code. Some I could catch are: 1. You aren't adding...
I think your problem lies in the use of a for loop in conjunction with the queue.remove() function. It seems like the `for x in queue:` operator runs into problems when you edit the list while it runs. I would recommend using `while queue:` instead and setting x to the first element. ``` while queue: x = ...
56,378,783
I'm doing a supposedly simple python challenge a friend gave me involving an elevator and the logic behind its movements. Everything was going well and good until I got to the point where I had to write how to determine if the elevator could move hit a called floor en route to its next queued floor. ```py def floorCom...
2019/05/30
[ "https://Stackoverflow.com/questions/56378783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10760049/" ]
The reason for the early exit is because you are modifying the list while looping on it. To have a simple example: ``` l = [3,6,9,10] for x in l: print(x) l.remove(x) ``` The output is ``` 3 9 ``` However, there are many other problems with your current code. Some I could catch are: 1. You aren't adding...
The reason for it to skip floor 6, is because of removing the data from the list, which is being iterated. ``` l=[3,6,9,10,14] for i in l: print(i) ``` Output: 3 6 9 10 14 ``` for i in l: print(i) l.remove(i) ``` output: 3 9 14
69,869,854
Can I get the `__doc__` string of the main script? Here is the starting script, which would be run from command line: `python a.py` module a.py ```py import b b.func() ``` module b.py ```py def func(): ???.__doc__ ``` How can I get the calling module, as an object? I am not asking about how to get the file...
2021/11/07
[ "https://Stackoverflow.com/questions/69869854", "https://Stackoverflow.com", "https://Stackoverflow.com/users/84196/" ]
a.py ``` """ Foo bar """ import b if __name__ == '__main__': b.show_your_docs() ``` b.py ``` def show_your_docs(): name = caller_name(1) print(__import__(name).__doc__) ``` Where caller\_name is code from this [gist](https://gist.github.com/techtonik/2151727#gistcomment-2333747) The weakness of this...
This is the full solution from @MatthewMartin 's accepted answer: ``` def show_your_docs(): name = caller_name(1) print(__import__(name).__doc__) def caller_docstring(level=1): name = caller_name(level) return __import__(name).__doc__ def caller_name(skip=2): def stack_(frame): ...
18,587,208
can any one tell me how to simulate touch on Image Button using android view client python
2013/09/03
[ "https://Stackoverflow.com/questions/18587208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2741623/" ]
Replace ``` android:src="res/drawable-hdpi/capture.PNG" ``` with ``` android:src="@drawable/capture" ``` Hope it helps.
change ``` android:src="res/drawable-hdpi/capture.PNG" ``` with ``` android:src="@drawable/capture" ```
18,587,208
can any one tell me how to simulate touch on Image Button using android view client python
2013/09/03
[ "https://Stackoverflow.com/questions/18587208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2741623/" ]
Replace ``` android:src="res/drawable-hdpi/capture.PNG" ``` with ``` android:src="@drawable/capture" ``` Hope it helps.
`android:src="@drawable/capture"` put this.
18,587,208
can any one tell me how to simulate touch on Image Button using android view client python
2013/09/03
[ "https://Stackoverflow.com/questions/18587208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2741623/" ]
try this, put capture.png in any drawable folder ``` android:src="@drawable/capture" ```
change ``` android:src="res/drawable-hdpi/capture.PNG" ``` with ``` android:src="@drawable/capture" ```
18,587,208
can any one tell me how to simulate touch on Image Button using android view client python
2013/09/03
[ "https://Stackoverflow.com/questions/18587208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2741623/" ]
try this, put capture.png in any drawable folder ``` android:src="@drawable/capture" ```
`android:src="@drawable/capture"` put this.
28,180,511
I wrote a simple triple quote print statement. See below. For the OVER lineart, it gets truncated into two different lines (when you copy paste this into the interpreter.) But, if I insert a space or any at the end of each of the lines, then it prints fine. Any idea why this behavior in python. I am inclined to think ...
2015/01/27
[ "https://Stackoverflow.com/questions/28180511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4500493/" ]
You have `\` backslash escapes in your string, one each on the last two lines as well as on the first line spelling *over*, all three part of the letter *R*. These signal to Python that you wanted to *ignore* the newline right after it. Either use a space right after each `\` backslash at the end of a line, *double* t...
The problem is with `\` at the end of line so you need to escape them. For that i use another backslash. ``` print( """ _____ ____ __ __ ______ / ____| / _ | / | /| | ____| | | / / | | / /| /| | | |___ | | _ / /__| | ...
54,914,306
This code fails when it runs: ``` import datetime import subprocess startdate = datetime.datetime(2010,4,9) for i in range(1): startdate += datetime.timedelta(days=1) enddate = datetime.datetime(2010,4,10) for i in range(1): enddate += datetime.timedelta(days=1) subprocess.call("sudo mam-list-usag...
2019/02/27
[ "https://Stackoverflow.com/questions/54914306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11035382/" ]
When possible, pass a *list* containing your command name and its arguments. ``` subprocess.call(["sudo", "mam-list-usagerecords", "-s", str(startdate), "-e", str(enddate), "--format", "csv", "--full"]) ``` This avoids the need to even know how the ...
When I first started using some of the subprocess methods I ran into some of the same issues. Try running your code like this: ``` import datetime import subprocess import shlex startdate = datetime.datetime(2010, 4, 9) + datetime.timedelta(days=1) enddate = datetime.datetime(2010, 4, 10) + datetime.timedelta(days=1...
34,999,726
Imagine I have an initializer with optional parameter ``` def __init__(self, seed = ...): ``` Now if parameter is not specified I want to provide a default value. But the seed is hard to calculate, so I have a class method that suggests the seed based on some class variables ``` MyClass.seedFrom(...) ``` Now how ...
2016/01/25
[ "https://Stackoverflow.com/questions/34999726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/982238/" ]
In case you only need to call `seedFrom` once, you can do so when `__init__` is defined. ``` class MyClass: # Defining seedFrom as a function outside # the class is also an option. Defining it # as a class method is not, since you still # have the problem of not having a class to # pass as the fir...
If you must do this in the **init** and want the seed method to be on the class, then you can make it a class method, eg as follows: ``` class SomeClass(object): defaultSeed = 255 @classmethod def seedFrom(cls, seed): pass # some seed def __init__(self, seed=None): self.seedFrom(seed...
4,011,526
I am a nurse and I know python but I am not an expert, just used it to process DNA sequences We got hospital records written in human languages and I am supposed to insert these data into a database or csv file but they are more than 5000 lines and this can be so hard. All the data are written in a consistent format...
2010/10/25
[ "https://Stackoverflow.com/questions/4011526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/485991/" ]
This uses [dateutil](http://labix.org/python-dateutil) to parse the date (e.g. '11/11/2010 - 09:00am'), and [parsedatetime](http://code.google.com/p/parsedatetime/) to parse the relative time (e.g. '4 hours later'): ``` import dateutil.parser as dparser import parsedatetime.parsedatetime as pdt import parsedatetime.pa...
Here are some possible way you can solve this - 1. **Using Regular Expressions** - Define them according to the patterns in your text. Match the expressions, extract pattern and you repeat for all records. This approach needs good understanding of the format in which the data is & of course regular expressions :) 2. ...
4,011,526
I am a nurse and I know python but I am not an expert, just used it to process DNA sequences We got hospital records written in human languages and I am supposed to insert these data into a database or csv file but they are more than 5000 lines and this can be so hard. All the data are written in a consistent format...
2010/10/25
[ "https://Stackoverflow.com/questions/4011526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/485991/" ]
Here are some possible way you can solve this - 1. **Using Regular Expressions** - Define them according to the patterns in your text. Match the expressions, extract pattern and you repeat for all records. This approach needs good understanding of the format in which the data is & of course regular expressions :) 2. ...
Maybe this can help you too , it's not tested ``` import collections import datetime import re retrieved_data = [] Data = collections.namedtuple('Patient', 'Sex, Symptoms, Death, Death_Time') dict_data = {'Death':'', 'Death_Time':'', 'Sex' :'', 'Symptoms':''} with open('data.t...
4,011,526
I am a nurse and I know python but I am not an expert, just used it to process DNA sequences We got hospital records written in human languages and I am supposed to insert these data into a database or csv file but they are more than 5000 lines and this can be so hard. All the data are written in a consistent format...
2010/10/25
[ "https://Stackoverflow.com/questions/4011526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/485991/" ]
Here are some possible way you can solve this - 1. **Using Regular Expressions** - Define them according to the patterns in your text. Match the expressions, extract pattern and you repeat for all records. This approach needs good understanding of the format in which the data is & of course regular expressions :) 2. ...
It would be relatively easy to do most of the processing with regards to sex, date/time, etc., as those before you have shown, since you can really just define a set of keywords that would indicate these things and use those keywords. However, the matter of processing symptoms is a bit different, as a definitive list ...
4,011,526
I am a nurse and I know python but I am not an expert, just used it to process DNA sequences We got hospital records written in human languages and I am supposed to insert these data into a database or csv file but they are more than 5000 lines and this can be so hard. All the data are written in a consistent format...
2010/10/25
[ "https://Stackoverflow.com/questions/4011526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/485991/" ]
This uses [dateutil](http://labix.org/python-dateutil) to parse the date (e.g. '11/11/2010 - 09:00am'), and [parsedatetime](http://code.google.com/p/parsedatetime/) to parse the relative time (e.g. '4 hours later'): ``` import dateutil.parser as dparser import parsedatetime.parsedatetime as pdt import parsedatetime.pa...
Maybe this can help you too , it's not tested ``` import collections import datetime import re retrieved_data = [] Data = collections.namedtuple('Patient', 'Sex, Symptoms, Death, Death_Time') dict_data = {'Death':'', 'Death_Time':'', 'Sex' :'', 'Symptoms':''} with open('data.t...
4,011,526
I am a nurse and I know python but I am not an expert, just used it to process DNA sequences We got hospital records written in human languages and I am supposed to insert these data into a database or csv file but they are more than 5000 lines and this can be so hard. All the data are written in a consistent format...
2010/10/25
[ "https://Stackoverflow.com/questions/4011526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/485991/" ]
This uses [dateutil](http://labix.org/python-dateutil) to parse the date (e.g. '11/11/2010 - 09:00am'), and [parsedatetime](http://code.google.com/p/parsedatetime/) to parse the relative time (e.g. '4 hours later'): ``` import dateutil.parser as dparser import parsedatetime.parsedatetime as pdt import parsedatetime.pa...
It would be relatively easy to do most of the processing with regards to sex, date/time, etc., as those before you have shown, since you can really just define a set of keywords that would indicate these things and use those keywords. However, the matter of processing symptoms is a bit different, as a definitive list ...
4,011,526
I am a nurse and I know python but I am not an expert, just used it to process DNA sequences We got hospital records written in human languages and I am supposed to insert these data into a database or csv file but they are more than 5000 lines and this can be so hard. All the data are written in a consistent format...
2010/10/25
[ "https://Stackoverflow.com/questions/4011526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/485991/" ]
Maybe this can help you too , it's not tested ``` import collections import datetime import re retrieved_data = [] Data = collections.namedtuple('Patient', 'Sex, Symptoms, Death, Death_Time') dict_data = {'Death':'', 'Death_Time':'', 'Sex' :'', 'Symptoms':''} with open('data.t...
It would be relatively easy to do most of the processing with regards to sex, date/time, etc., as those before you have shown, since you can really just define a set of keywords that would indicate these things and use those keywords. However, the matter of processing symptoms is a bit different, as a definitive list ...
49,100,167
So I'm optimizing a game playing bot and have run out of optimizations in pure python. Currently, most of the time is spent translating one game state into the next game state for the alpha-beta search. The current thinking is that I could speed this up by writing the state-transition code in C. My problem comes from t...
2018/03/04
[ "https://Stackoverflow.com/questions/49100167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/409106/" ]
This is not the expected behaviour. Components that do not change should not re-execute the mounted hook. I would search for the problem someplace in the top of the vue component hierarchy, because it sounds like some other piece of code might force the re-rendering of the hierarchy.
When router's path changes, components will mount again,if you want to mount component only one time, you can try the Vue's build-in component **keep-alive**, it will only trigger its activated hook and deactivated hook.And you can do something in these two hooks. **The html:** ``` <div id="app"> <router-link t...
74,009,340
My question is similar to this([Python sum on keys for List of Dictionaries](https://stackoverflow.com/questions/8584504/python-sum-on-keys-for-list-of-dictionaries)), but need to sum up the values based on two or more key-value elements. I have a list of dictionaries as following: ``` list_to_sum= [{'Name': '...
2022/10/10
[ "https://Stackoverflow.com/questions/74009340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20188249/" ]
You could create a [`collections.Counter`](https://docs.python.org/3/library/collections.html#collections.Counter).Then you can simply add the values as the appear using the tuple as `(Name, City)` as the key: ``` from collections import Counter list_to_sum=[ {'Name': 'A', 'City': 'W','amt':100}, {'Name': 'B'...
``` list_to_sum = [{'Name': 'A', 'City': 'W', 'amt': 100}, {'Name': 'B', 'City': 'A', 'amt': 200}, {'Name': 'A', 'City': 'W', 'amt': 300}, {'Name': 'C', 'City': 'X', 'amt': 400}, {'Name': 'C', 'City': 'X', 'amt': 500}, {'Name': 'A', 'City': 'W',...
74,009,340
My question is similar to this([Python sum on keys for List of Dictionaries](https://stackoverflow.com/questions/8584504/python-sum-on-keys-for-list-of-dictionaries)), but need to sum up the values based on two or more key-value elements. I have a list of dictionaries as following: ``` list_to_sum= [{'Name': '...
2022/10/10
[ "https://Stackoverflow.com/questions/74009340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20188249/" ]
You could create a [`collections.Counter`](https://docs.python.org/3/library/collections.html#collections.Counter).Then you can simply add the values as the appear using the tuple as `(Name, City)` as the key: ``` from collections import Counter list_to_sum=[ {'Name': 'A', 'City': 'W','amt':100}, {'Name': 'B'...
Besides the answers proposed by the others, it can be done in a pandas one-liner. It groups rows by name and city and calculates the sum over their amt feature. ```py import pandas as pd list_to_sum=[ {'Name': 'A', 'City': 'W','amt':100}, {'Name': 'B', 'City': 'A','amt':200}, {'Name': 'A', 'City': 'W','amt...
50,692,816
I am getting the following SSL issue when running pip install: ``` python -m pip install zeep Collecting zeep Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError("bad handshake: Error([('SSL routines', 'ssl3_get_server_certificate', 'certific...
2018/06/05
[ "https://Stackoverflow.com/questions/50692816", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1045057/" ]
I was able to resolve the issue by using the following: ``` python -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org --index-url=https://pypi.org/simple/ zeep ```
If using windows then make sure the below three paths are added in Windows environment variable : 1. ....\Anaconda\Library\bin 2. ....\Anaconda\Scripts 3. ....\Anaconda If not using Anaconda then in place of Anaconda the path where python is installed.
64,251,311
First post so be gentle please. I have a bash script running on a Linux server which does a daily sftp download of an Excel file. The file is moved to a Windows share. An additional requirement has arisen in that i'd like to add the number of rows to the filename which is also timestamped so different each day. Ideall...
2020/10/07
[ "https://Stackoverflow.com/questions/64251311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14409634/" ]
Assuming we put your python into a separate script file, something like: ```py # count_script.py import sys import pandas as pd excel_file = pd.ExcelFile(sys.argv[1]) df = excel_file.parse('mysheet') print(df[['code']].count().at(0)) ``` We could then easily call that script from within the bash script that invoked...
You can pass command-line arguments to python programs, by invoking them as such: ``` python3 script.py argument1 argument2 ... argumentn ``` They can then be accessed within the script using `sys.argv`. You must `import sys` before using it. `sys.argv[0]` is the name of the python script, and the rest are the addit...
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
Use **shutil.copy2** instead of **shutil.copyfile** ``` import shutil shutil.copy2('/src/dir/file.ext','/dst/dir/newname.ext') # file copy to another file shutil.copy2('/src/file.ext', '/dst/dir') # file copy to diff directory ```
well the questionis old, for new viewer of Python 3.6 use ``` shutil.copyfile( "D:\Out\myfile.txt", "D:\In" ) ``` instead of ``` shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) ``` `r` argument is passed for reading file not for copying
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
Use **shutil.copy2** instead of **shutil.copyfile** ``` import shutil shutil.copy2('/src/dir/file.ext','/dst/dir/newname.ext') # file copy to another file shutil.copy2('/src/file.ext', '/dst/dir') # file copy to diff directory ```
Make sure you aren't in (locked) any of the the files you're trying to use shutil.copy in. This should assist in solving your problem
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
First of all, make sure that your files aren't locked by Windows, some applications, like MS Office, locks the oppened files. I got erro 13 when i was is trying to rename a long file list in a directory, but Python was trying to rename some folders that was at the same path of my files. So, if you are not using shutil...
well the questionis old, for new viewer of Python 3.6 use ``` shutil.copyfile( "D:\Out\myfile.txt", "D:\In" ) ``` instead of ``` shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) ``` `r` argument is passed for reading file not for copying
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
use shutil.copy instead of shutil.copyfile example: ``` shutil.copy(PathOf_SourceFileName.extension,TargetFolderPath) ```
I solved this problem, you should be the complete target file name for destination destination = pathdirectory + filename.\* I use this code fir copy wav file with shutil : ``` # open file with QFileDialog browse_file = QFileDialog.getOpenFileName(None, 'Open file', 'c:', "wav files (*.wav)") # get fi...
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
I solved this problem, you should be the complete target file name for destination destination = pathdirectory + filename.\* I use this code fir copy wav file with shutil : ``` # open file with QFileDialog browse_file = QFileDialog.getOpenFileName(None, 'Open file', 'c:', "wav files (*.wav)") # get fi...
Visual Studio 2019 Solution : Administrator provided full Access to this folder "C:\ProgramData\Docker" it is working. > > ERROR: File IO error seen copying files to volume: edgehubdev. Errno: 13, Error Permission denied : [Errno 13] Permission denied: 'C:\ProgramData\Docker\volumes\edgehubdev\\_data\edge-chain-ca.c...
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
Read the [docs](http://docs.python.org/library/shutil.html#shutil.copyfile): > > `shutil.copyfile(src, dst)` > > > Copy the contents (no metadata) of the file named *src* to a file > named *dst*. *dst* must be the **complete target file name**; look at `copy()` > for a copy that accepts a target directory path. >...
Use **shutil.copy2** instead of **shutil.copyfile** ``` import shutil shutil.copy2('/src/dir/file.ext','/dst/dir/newname.ext') # file copy to another file shutil.copy2('/src/file.ext', '/dst/dir') # file copy to diff directory ```
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
use shutil.copy instead of shutil.copyfile example: ``` shutil.copy(PathOf_SourceFileName.extension,TargetFolderPath) ```
Make sure you aren't in (locked) any of the the files you're trying to use shutil.copy in. This should assist in solving your problem
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
I solved this problem, you should be the complete target file name for destination destination = pathdirectory + filename.\* I use this code fir copy wav file with shutil : ``` # open file with QFileDialog browse_file = QFileDialog.getOpenFileName(None, 'Open file', 'c:', "wav files (*.wav)") # get fi...
This works for me: ``` import os import shutil import random dir = r'E:/up/2000_img' output_dir = r'E:/train_test_split/out_dir' files = [file for file in os.listdir(dir) if os.path.isfile(os.path.join(dir, file))] if len(files) < 200: # for file in files: # shutil.copyfile(os.path.join(dir, file), dst)...
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
use shutil.copy instead of shutil.copyfile example: ``` shutil.copy(PathOf_SourceFileName.extension,TargetFolderPath) ```
well the questionis old, for new viewer of Python 3.6 use ``` shutil.copyfile( "D:\Out\myfile.txt", "D:\In" ) ``` instead of ``` shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) ``` `r` argument is passed for reading file not for copying
7,518,067
I have two folders: In, Out - it is not system folder on disk D: - Windows 7. Out contain "myfile.txt" I run the following command in python: ``` >>> shutil.copyfile( r"d:\Out\myfile.txt", r"D:\In" ) Traceback (most recent call last): File "<pyshell#39>", line 1, in <module> shutil.copyfile( r"d:\Out\myfile.txt...
2011/09/22
[ "https://Stackoverflow.com/questions/7518067", "https://Stackoverflow.com", "https://Stackoverflow.com/users/490908/" ]
use shutil.copy instead of shutil.copyfile example: ``` shutil.copy(PathOf_SourceFileName.extension,TargetFolderPath) ```
use ``` > from shutil import copyfile > > copyfile(src, dst) ``` for src and dst use: ``` srcname = os.path.join(src, name) dstname = os.path.join(dst, name) ```
41,857,659
My python code works correctly in the below example. My code combines a directory of CSV files and matches the headers. However, I want to take it a step further - how do I add a column that appends the filename of the CSV that was used? ``` import pandas as pd import glob globbed_files = glob.glob("*.csv") #creates ...
2017/01/25
[ "https://Stackoverflow.com/questions/41857659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6067066/" ]
This should work: ``` import os for csv in globbed_files: frame = pd.read_csv(csv) frame['filename'] = os.path.basename(csv) data.append(frame) ``` `frame['filename']` creates a new column named `filename` and `os.path.basename()` turns a path like `/a/d/c.txt` into the filename `c.txt`.
Mike's answer above works perfectly. In case any googlers run into the following error: ``` >>> TypeError: cannot concatenate object of type "<type 'str'>"; only pd.Series, pd.DataFrame, and pd.Panel (deprecated) objs are valid ``` It's possibly because the separator is not correct. I was using a custom csv fil...
41,857,659
My python code works correctly in the below example. My code combines a directory of CSV files and matches the headers. However, I want to take it a step further - how do I add a column that appends the filename of the CSV that was used? ``` import pandas as pd import glob globbed_files = glob.glob("*.csv") #creates ...
2017/01/25
[ "https://Stackoverflow.com/questions/41857659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6067066/" ]
This should work: ``` import os for csv in globbed_files: frame = pd.read_csv(csv) frame['filename'] = os.path.basename(csv) data.append(frame) ``` `frame['filename']` creates a new column named `filename` and `os.path.basename()` turns a path like `/a/d/c.txt` into the filename `c.txt`.
files variable contains all list of csv files in your present directory. Such as `['FileName1.csv',FileName2.csv']`. You also need to remove `".csv"`. You can use `.split()` function. Below is simple logic. This will work for you. ``` files = glob.glob("*.csv") for i in files: df=pd.read_csv(i) df['New Colum...
34,971,363
I am heavily using python threading, and my many use-cases require that I would log separate task executions under different logger names. A typical code example would be: ``` def task(logger=logger): global_logger.info('Task executing') for item in [subtask(x) for x in range(100000)]: # While debuggi...
2016/01/24
[ "https://Stackoverflow.com/questions/34971363", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1055356/" ]
Because loggers inherit their parent's level if not explicitly set, you could just do e.g. ``` root_name = global_logger.name logging.getLogger(root_name + '.main.task').setLevel(logging.INFO) ``` and that would mean that all child loggers inherit that level, unless a level were explicitly set for one of them. Note...
I was having the same issue suppressing the output from the `BAC0` library. I tried changing the parent logger and that did not update the children (Python 3.9) This answer is based on the accepted answer in this post: [How to list all existing loggers using python.logging module](https://stackoverflow.com/questions/5...
35,204,703
one script starts automatically when my raspberry is booted up, within this script there is motion sensor, if detected, it starts a subproces camera.py (recording a video, then converts the video and emails) within the main script that starts u on booting up, there is another if statement, if button pressed then stop ...
2016/02/04
[ "https://Stackoverflow.com/questions/35204703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5794219/" ]
Use `pkill`: ``` $ sudo pkill -f camera.py ```
If you make camera.py executable, put it on your $PATH and make line 1 of the script `#!/usr/bin/python`, then execute camera.py without the python command in front of it, your `"sudo killall camera.py"` command should work.
35,204,703
one script starts automatically when my raspberry is booted up, within this script there is motion sensor, if detected, it starts a subproces camera.py (recording a video, then converts the video and emails) within the main script that starts u on booting up, there is another if statement, if button pressed then stop ...
2016/02/04
[ "https://Stackoverflow.com/questions/35204703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5794219/" ]
If you make camera.py executable, put it on your $PATH and make line 1 of the script `#!/usr/bin/python`, then execute camera.py without the python command in front of it, your `"sudo killall camera.py"` command should work.
instead of using: ``` import os os.system("raspivid -n -o /home/pi/viseo.h264 -t 10000") os.system(.... python script0.py) os.system(.... python script1.py) ``` you should use the same Popen structure as how you spawn this process. This gives you access to the Popen object of the calls. ``` import os pvid = subpro...
35,204,703
one script starts automatically when my raspberry is booted up, within this script there is motion sensor, if detected, it starts a subproces camera.py (recording a video, then converts the video and emails) within the main script that starts u on booting up, there is another if statement, if button pressed then stop ...
2016/02/04
[ "https://Stackoverflow.com/questions/35204703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5794219/" ]
Use `pkill`: ``` $ sudo pkill -f camera.py ```
instead of using: ``` import os os.system("raspivid -n -o /home/pi/viseo.h264 -t 10000") os.system(.... python script0.py) os.system(.... python script1.py) ``` you should use the same Popen structure as how you spawn this process. This gives you access to the Popen object of the calls. ``` import os pvid = subpro...
40,866,883
I use python 3.4 , pyQt5 and Qt designer (Winpython distribution). I like the idea of making guis by designer and importing them in python with setupUi. I'm able to show MainWindows and QDialogs. However, now I would like to set my MainWindow, always on top and with the close button only. I know this can be done by set...
2016/11/29
[ "https://Stackoverflow.com/questions/40866883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491532/" ]
Every call of `setWindowFlags` will completely override the current settings, so you need to set all the flags at once. Also, you must include the `CustomizeWindowHint` flag, otherwise all the other hints will be ignored. The following will probably work on Windows: ``` self.setWindowFlags( QtCore.Qt.Windo...
I would propose a different solution, because it keeps the existing flags. Reason to do this, is to NOT mingle with UI-specific presets (like that a dialog has not by default a "maximize" or "minimize" button). ``` self.setWindowFlags(self.windowFlags() # reuse initial flags & ~QtCore.Qt.WindowContextHelpButtonHin...
47,689,456
I was trying to connect oracle database using python like below. ``` import cx_Oracle conn = cx_Oracle.connect('user/password@host:port/database') ``` I've faced an error when connecting oracle. DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No ...
2017/12/07
[ "https://Stackoverflow.com/questions/47689456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3176741/" ]
That error indicates that you are missing a 64-bit Oracle client installation or it hasn't been configured correctly. Take a look at the link mentioned in the error message. It will give instructions on how to perform the Oracle client installation and configuration. [Update on behalf of Anthony: his latest cx\_Oracle...
This seems a problem with version 6.X.This problem didnot appeared in 5.X.But for my case a little workaround worked.I installed in my physical machine and only thing that i need to do was a pc reboot or reopen the terminal as i have added in the path of environment variables.You can try to install in physical machine ...
47,689,456
I was trying to connect oracle database using python like below. ``` import cx_Oracle conn = cx_Oracle.connect('user/password@host:port/database') ``` I've faced an error when connecting oracle. DatabaseError: DPI-1047: 64-bit Oracle Client library cannot be loaded: "libclntsh.so: cannot open shared object file: No ...
2017/12/07
[ "https://Stackoverflow.com/questions/47689456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3176741/" ]
This seems a problem with version 6.X.This problem didnot appeared in 5.X.But for my case a little workaround worked.I installed in my physical machine and only thing that i need to do was a pc reboot or reopen the terminal as i have added in the path of environment variables.You can try to install in physical machine ...
Here is the full program to connect Oracle using python. First, you need to install cx\_Oracle. to install it fire the below command. `pip install cx_Oracle` ```js import cx_Oracle def get_databse_coonection(): try: host='hostName' port ='portnumber' serviceName='sid of you database'...