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
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` To also convert floats 0 .. 1 to uint8 s, ``` rgb_uint8 = (np.dstack((r,g,b)) * 255.999) .astype(np.uint8) # right, Janna, not 256 ```
If using PIL Image convert it to array and then proceed with the below, else using matplotlib or cv2 perform directly. ``` image = cv2.imread('')[:,:,::-1] image_2 = image[10:150,10:100] print(image_2.shape) img_r = image_2[:,:,0] img_g = image_2[:,:,1] img_b = image_2[:,:,2] image_2 = img_r*0.2989 + 0.587*img_g + 0...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` To also convert floats 0 .. 1 to uint8 s, ``` rgb_uint8 = (np.dstack((r,g,b)) * 255.999) .astype(np.uint8) # right, Janna, not 256 ```
Your distortion i believe is caused by the way you are splitting your original image into its individual bands and then resizing it again before putting it into merge; ``` ` image=Image.open("your image") print(image.size) #size is inverted i.e columns first rows second eg: 500,250 #convert to array li_r=list(image...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` This code doesnt create 3d array if you pass 3 channels. 2 channels remain.
If using PIL Image convert it to array and then proceed with the below, else using matplotlib or cv2 perform directly. ``` image = cv2.imread('')[:,:,::-1] image_2 = image[10:150,10:100] print(image_2.shape) img_r = image_2[:,:,0] img_g = image_2[:,:,1] img_b = image_2[:,:,2] image_2 = img_r*0.2989 + 0.587*img_g + 0...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` To also convert floats 0 .. 1 to uint8 s, ``` rgb_uint8 = (np.dstack((r,g,b)) * 255.999) .astype(np.uint8) # right, Janna, not 256 ```
I don't really understand your question but here is an example of something similar I've done recently that seems like it might help: ``` # r, g, and b are 512x512 float arrays with values >= 0 and < 1. from PIL import Image import numpy as np rgbArray = np.zeros((512,512,3), 'uint8') rgbArray[..., 0] = r*256 rgbArray...
10,443,295
So I have a set of data which I am able to convert to form separate numpy arrays of R, G, B bands. Now I need to combine them to form an RGB image. I tried 'Image' to do the job but it requires 'mode' to be attributed. I tried to do a trick. I would use Image.fromarray() to take the array to image but it attains 'F...
2012/05/04
[ "https://Stackoverflow.com/questions/10443295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1372149/" ]
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` To also convert floats 0 .. 1 to uint8 s, ``` rgb_uint8 = (np.dstack((r,g,b)) * 255.999) .astype(np.uint8) # right, Janna, not 256 ```
``` rgb = np.dstack((r,g,b)) # stacks 3 h x w arrays -> h x w x 3 ``` This code doesnt create 3d array if you pass 3 channels. 2 channels remain.
58,642,357
I am trying to automate the login to the following page using selenium: <https://services.cal-online.co.il/Card-Holders/SCREENS/AccountManagement/Login.aspx?ReturnUrl=%2fcard-holders%2fScreens%2fAccountManagement%2fHomePage.aspx> Trying to find the elements of username and password using both id, css selector and xpat...
2019/10/31
[ "https://Stackoverflow.com/questions/58642357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9608607/" ]
To automate the login to the [page](https://services.cal-online.co.il/Card-Holders/SCREENS/AccountManagement/Login.aspx?ReturnUrl=%2fcard-holders%2fScreens%2fAccountManagement%2fHomePage.aspx) using [Selenium](https://stackoverflow.com/questions/54459701/what-is-selenium-and-what-is-webdriver/54482491#54482491) as the ...
found a solution to the problem. the problem really was that the object is inside an iframe. I tried to use the solution suggested in [Get element from within an iFrame](https://stackoverflow.com/questions/1088544/get-element-from-within-an-iframe) but got a security error. the solution is to switch frame the follwoin...
29,574,698
I'm looking to split a given string into a list with elements of equal length, I have found a code segment that works in versions earlier than python 3 which is the only version I am familiar with. ``` string = "abcdefghijklmnopqrstuvwx" string = string.Split(0 - 3) print(string) >>> ["abcd", "efgh", "ijkl", "mnop",...
2015/04/11
[ "https://Stackoverflow.com/questions/29574698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4776196/" ]
You could try the `.clip()` function. You can use `.save()` to save the state to `.restore()` after the clip so it isn't destructive. You can set the path to whatever you would like and it will create a vector mask of that shape. ``` var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d...
Try something like this ``` context.fillStyle = "rgba(255, 255, 255, 1)"; context.fillRect(0, 100, 400, 400); context.fillStyle = "rgba(255, 255, 255, 1)"; context.fillRect(100, 0, 400, 400); ``` <http://jsfiddle.net/xqzxawyb/1/>
29,574,698
I'm looking to split a given string into a list with elements of equal length, I have found a code segment that works in versions earlier than python 3 which is the only version I am familiar with. ``` string = "abcdefghijklmnopqrstuvwx" string = string.Split(0 - 3) print(string) >>> ["abcd", "efgh", "ijkl", "mnop",...
2015/04/11
[ "https://Stackoverflow.com/questions/29574698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4776196/" ]
If your "complex shape" is defined in a path command (like the square path command in your example--only your path is more complex), then you can use compositing to eliminate all but the pixels inside the path: (1) Define your path and fill it with a solid color, (2) Set compositing to source-in which will draw new...
Try something like this ``` context.fillStyle = "rgba(255, 255, 255, 1)"; context.fillRect(0, 100, 400, 400); context.fillStyle = "rgba(255, 255, 255, 1)"; context.fillRect(100, 0, 400, 400); ``` <http://jsfiddle.net/xqzxawyb/1/>
29,574,698
I'm looking to split a given string into a list with elements of equal length, I have found a code segment that works in versions earlier than python 3 which is the only version I am familiar with. ``` string = "abcdefghijklmnopqrstuvwx" string = string.Split(0 - 3) print(string) >>> ["abcd", "efgh", "ijkl", "mnop",...
2015/04/11
[ "https://Stackoverflow.com/questions/29574698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4776196/" ]
You could try the `.clip()` function. You can use `.save()` to save the state to `.restore()` after the clip so it isn't destructive. You can set the path to whatever you would like and it will create a vector mask of that shape. ``` var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d...
``` <canvas id="myCanvas" width="100" height="100" style="border:1px solid #d3d3d3;"> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.rect(0,0,100,100); ctx.stroke(); ``` DEMO : <http://jsfiddle.net/q776zjdx/>
29,574,698
I'm looking to split a given string into a list with elements of equal length, I have found a code segment that works in versions earlier than python 3 which is the only version I am familiar with. ``` string = "abcdefghijklmnopqrstuvwx" string = string.Split(0 - 3) print(string) >>> ["abcd", "efgh", "ijkl", "mnop",...
2015/04/11
[ "https://Stackoverflow.com/questions/29574698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4776196/" ]
If your "complex shape" is defined in a path command (like the square path command in your example--only your path is more complex), then you can use compositing to eliminate all but the pixels inside the path: (1) Define your path and fill it with a solid color, (2) Set compositing to source-in which will draw new...
``` <canvas id="myCanvas" width="100" height="100" style="border:1px solid #d3d3d3;"> var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.rect(0,0,100,100); ctx.stroke(); ``` DEMO : <http://jsfiddle.net/q776zjdx/>
29,574,698
I'm looking to split a given string into a list with elements of equal length, I have found a code segment that works in versions earlier than python 3 which is the only version I am familiar with. ``` string = "abcdefghijklmnopqrstuvwx" string = string.Split(0 - 3) print(string) >>> ["abcd", "efgh", "ijkl", "mnop",...
2015/04/11
[ "https://Stackoverflow.com/questions/29574698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4776196/" ]
You could try the `.clip()` function. You can use `.save()` to save the state to `.restore()` after the clip so it isn't destructive. You can set the path to whatever you would like and it will create a vector mask of that shape. ``` var canvas = document.getElementById('myCanvas'); var context = canvas.getContext('2d...
If your "complex shape" is defined in a path command (like the square path command in your example--only your path is more complex), then you can use compositing to eliminate all but the pixels inside the path: (1) Define your path and fill it with a solid color, (2) Set compositing to source-in which will draw new...
68,402,859
I am using python API to save and download model from MinIO. This is a MinIO installed on my server. The data is in binary format. ``` a = 'Hello world!' a = pickle.dumps(a) client.put_object( bucket_name='my_bucket', object_name='my_object', data=io.BytesIO(a), ...
2021/07/16
[ "https://Stackoverflow.com/questions/68402859", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8797308/" ]
Try with response.data.decode()
The response is a `urllib3.response.HTTPResponse` object. See [urllib3 Documentation](https://urllib3.readthedocs.io/en/latest/reference/urllib3.response.html): > > Backwards-compatible with http.client.HTTPResponse but the response body is loaded and decoded on-demand when the data property is accessed. > > > ...
45,406,332
I am very new to SQLAlchemy. I am having some difficulty setting up a one to many relationship between two models in my application. I have two models User `Photo'. A user has only one role associated with it and a role has many users associated with it. This is the code that I have in my data\_generator.py file: ```...
2017/07/31
[ "https://Stackoverflow.com/questions/45406332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7954998/" ]
There might be three relationships between User and Role: * One to One(One user has only one Role) * Many to One(One user has many roles) * Many to Many(Many user has many roles) For One to One: ``` class Role(Base): id = Column(Integer, primary_key=True) # ... user_id = Column(Integer, ForeignKey("us...
I made a low-level mistake because of my lack of database and SQL alchemy. First of all, this is a typical "one to many" problem.Relationship connects two rows from two tables by users' foreign key. The role\_id is defined as the foreign key, which builds the connections. The parameter "roles.id" in "ForeignKey()" clar...
10,213,509
I have a **Django** site, hosted on **Heroku**. One of the models has an image field, that takes uploaded images, resizes them, and pushes them to Amazon S3 so that they can be stored persistently. This is working well, using **PIL** ``` def save(self, *args, **kwargs): # Save this one super(Product, self)...
2012/04/18
[ "https://Stackoverflow.com/questions/10213509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/267757/" ]
I use this PIL fork in requirements.txt: ``` -e hg+https://bitbucket.org/etienned/pil-2009-raclette/#egg=PIL ``` and can use JPEG without issues: ``` -------------------------------------------------------------------- PIL 1.2a0 SETUP SUMMARY ----------------------------------------------------...
Also please consider using [Pillow](https://pypi.python.org/pypi/Pillow), the "friendly" PIL fork which offers: * Setuptools compatibility * Python 3 compatibility * Frequent release cycle * Many bug fixes
25,433,921
I need to run this file: ``` from apps.base.models import Event from apps.base.models import ProfileActiveUntil from django.template import Context from django.db.models import Q import datetime from django.core.mail import EmailMultiAlternatives from bonzer.settings import SITE_HOST import smtplib from email.mime.mul...
2014/08/21
[ "https://Stackoverflow.com/questions/25433921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3216697/" ]
`cron` does not read rc shell files so you need to define the enviroment variable PYTHONPATH to include the location of the `apps` package and all other module files that are required by the script. ``` PYTHONPATH=/usr/local/lib/python2.7:/usr/lib/python2.7 */2 * * * * /usr/local/bin/python2.7 /home/nezap/webapps/bonz...
I would assume this is a problem with your cwd (current working directory). An easy way to test this would be to go to the root (cd /) then run: ``` python2.7 /home/nezap/webapps/bonzer/bonzer/apps/base/alert.py ``` You should get the same error. The path you will want to use will depend on the place where you norma...
25,496,012
The answers to [this question](https://stackoverflow.com/questions/14043886/python-2-3-convert-integer-to-bytes-cleanly) make it seem like there are two ways to convert an integer to a `bytes` object in Python 3. They show `s = str(n).encode()` and ``` n = 5 bytes( [n] ) ``` Being the same. However, testing th...
2014/08/25
[ "https://Stackoverflow.com/questions/25496012", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3291506/" ]
Those two examples are *not* equivalent. `str(n).encode()` takes whatever you give it, turns it into its string representation, and then encodes using a character codec like utf8. `bytes([..])` will form a bytestring with the byte values of the array given. The representation `\xFF` is in fact the hexadecimal represent...
`b'8'` is a `bytes` object which contains a single byte with value of the character `'8'` which is equal to `56`. `b'\x08'` is a `bytes` object which contains a single byte with value `8`, which is the same as `0x8`.
30,637,387
I'm running Notebook server on remote machine and want to somehow protect it. Unfortunately I cannot use password authentication (because if I do so then I can't use `ein`, an emacs package for ipython notebooks). The other obvious solution is to make IPython Notebook accept connections only from my local machine's ip...
2015/06/04
[ "https://Stackoverflow.com/questions/30637387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2500596/" ]
You can set the port for iPython to a port that will only be used by iPython. And then restrict access to that port to only you local machine's IP. To set the port: Edit the ipython\_notebook\_config.py file and insert or edit the line: ``` c.NotebookApp.port = 7777 ``` where you change 7777 to the port of your ch...
I dont found anything about other authentication way on ipython website, then you can have right. Here <http://ipython.org/ipython-doc/3/notebook/security.html> is something about ipython trust. Maybe it will be sufficient for you.
56,476,940
I have successfully installed z3 on a remote server where I am not root. when I try to run my python code I get : ``` ModuleNotFoundError: No module named 'z3' ``` I understand that I have to add it to PYTHONPATH in order to work and so I went ahead and done that like this: > > export PYTHONPATH=$HOME/usr/lib/pyth...
2019/06/06
[ "https://Stackoverflow.com/questions/56476940", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10881142/" ]
Did you pass the `--python` flag when you called `scripts/mk_make.py`? See the instructions on <https://github.com/Z3Prover/z3/blob/master/README.md> on how to exactly enable Python (about all the way down in that page). Here's an example invocation: ``` python scripts/mk_make.py --prefix=/home/leo --python --pypkgdi...
For Windows users that just downloaded and unzipped the compiled Z3 binary into some arbitrary directory, adding the location of the python directory in the directory where Z3 was installed to PYTHONPATH did the trick. ie in Cygwin : `$ export PYTHONPATH=<location of z3>/bin/python:$PYTHONPATH` (or the equivalent in a ...
43,168,078
I am trying to extract how many songs are release in every year from csv. my data looks like this ``` no,artist,name,year "1","Bing Crosby","White Christmas","1942" "2","Bill Haley & his Comets","Rock Around the Clock","1955" "3","Sinead O'Connor","Nothing Compares 2 U","1990","35.554" "4","Celine Dion","My Heart Wil...
2017/04/02
[ "https://Stackoverflow.com/questions/43168078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7438144/" ]
2 very simple lines of code: ``` import pandas as pd my_csv=pd.read_csv(filename) ``` and to get the number of songs per year: ``` songs_per_year= my_csv.groupby('year')['name'].count() ```
You can use a `Counter` object from the [`collections`](https://docs.python.org/2/library/collections.html) module.. ``` >>> from collections import Counter >>> from csv import reader >>> >>> YEAR = 3 >>> with open('file.txt') as f: ... next(f, None) # discard header ... year2rel = Counter(int(line[YEAR]) for...
70,946,840
Is it possible to make a dot function that is var.function() that changes var? I realise that i can do: ``` class Myclass: def function(x): return 2 Myclass.function(1): ``` But i want to change it like the default python function. ``` def function(x): return(3) x=1 x.function() print(x) ``` and it re...
2022/02/01
[ "https://Stackoverflow.com/questions/70946840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18093990/" ]
You can use Pandas `.shift()` to compare the values of the series with the next row, build up a session value based on the "hops", and then group by that session value. ``` import pandas as pd df = pd.DataFrame({ 'name' : ['John', 'John', 'John', 'John', 'John', 'Emily', 'Emily', 'John'], 'app' : ['Excel...
One solution would be to add a column to define hops. Then group by that column ``` hop_id = 1 for i in df.index: df.loc[i,'hop_id'] = hop_id if (df.loc[i,'Name']!= df.loc[i+1,'Name']) or (df.loc[i,'Application'] != df.loc[i+1,'Application']): hop_id = hop_id +1 df.groupby('hop_id')['Duration'].sum() ...
67,415,482
I created a Sudoku class in python, I want to solve the board and also keep an instance variable with the original board, but when I use the `solve()` method which uses the recursive backtracking algorithm `self.board` changes together with `self.solved_board` why is that, and how can I keep a variable with the origina...
2021/05/06
[ "https://Stackoverflow.com/questions/67415482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7311644/" ]
`self.solved_board = board[:]` does indeed create a new list, but it references the same inner lists as `board`. You need to go one level deeper: ``` self.solved_board = [row[:] for row in board] ```
Yeah, `board[:]` does create a new list -- of all those old inner lists: ```py In [23]: board = [[1], [2]] In [24]: board2 = board[:] In [25]: board2[0] is board[0] Out[25]: True In [26]: board2[0][0] += 10 In [28]: board Out[28]: [[11], [2]] ``` You'd need to deepcopy it; e.g., ```py solved_board = [row[:] for...
67,415,482
I created a Sudoku class in python, I want to solve the board and also keep an instance variable with the original board, but when I use the `solve()` method which uses the recursive backtracking algorithm `self.board` changes together with `self.solved_board` why is that, and how can I keep a variable with the origina...
2021/05/06
[ "https://Stackoverflow.com/questions/67415482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7311644/" ]
Yeah, `board[:]` does create a new list -- of all those old inner lists: ```py In [23]: board = [[1], [2]] In [24]: board2 = board[:] In [25]: board2[0] is board[0] Out[25]: True In [26]: board2[0][0] += 10 In [28]: board Out[28]: [[11], [2]] ``` You'd need to deepcopy it; e.g., ```py solved_board = [row[:] for...
Try deepcopy method ``` from copy import deepcopy def __init__(self, board): self.board = board self.solved_board = deepcopy(board) ```
67,415,482
I created a Sudoku class in python, I want to solve the board and also keep an instance variable with the original board, but when I use the `solve()` method which uses the recursive backtracking algorithm `self.board` changes together with `self.solved_board` why is that, and how can I keep a variable with the origina...
2021/05/06
[ "https://Stackoverflow.com/questions/67415482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7311644/" ]
`self.solved_board = board[:]` does indeed create a new list, but it references the same inner lists as `board`. You need to go one level deeper: ``` self.solved_board = [row[:] for row in board] ```
Try deepcopy method ``` from copy import deepcopy def __init__(self, board): self.board = board self.solved_board = deepcopy(board) ```
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
Ok, I answer my own question : I'm dumb :-) ``` ls /usr/bin/ipython* /usr/bin/ipython /usr/bin/ipython2.4 /usr/bin/ipython2.5 ``` Now it's built-in...
To complement on @Peter's answer, I might add that the ipython "executable" you run are simply python script that launch the ipython shell. So a solution that worked for me was to change the python version that runs that script: ```bash $ cp ipython ipython3 $ nano ipython3 ``` Here is what the script looks like: `...
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
Ok, I answer my own question : I'm dumb :-) ``` ls /usr/bin/ipython* /usr/bin/ipython /usr/bin/ipython2.4 /usr/bin/ipython2.5 ``` Now it's built-in...
I'm using Ubuntu 10.10 and there's only on ipython installed. (There's also only one python available, but I got an older version with [the deadsnakes ppa](https://launchpad.net/~fkrull/+archive/deadsnakes).) To get ipython2.5, I installed ipython from your virtualenv: ``` virtualenv --python=/usr/bin/python2.5 proje...
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
I find the simplest way to specify which python version to use is to explicitly call the ipython script using that version. To do this, you may need to know the path to the ipython script, which you can find by running `which ipython`. Then simply run `python <path-to-ipython>` to start ipython.
To complement on @Peter's answer, I might add that the ipython "executable" you run are simply python script that launch the ipython shell. So a solution that worked for me was to change the python version that runs that script: ```bash $ cp ipython ipython3 $ nano ipython3 ``` Here is what the script looks like: `...
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
I'm using Ubuntu 10.10 and there's only on ipython installed. (There's also only one python available, but I got an older version with [the deadsnakes ppa](https://launchpad.net/~fkrull/+archive/deadsnakes).) To get ipython2.5, I installed ipython from your virtualenv: ``` virtualenv --python=/usr/bin/python2.5 proje...
You can just: ``` $ python2.4 setup.py install --prefix=$HOME/usr $ python2.5 setup.py install --prefix=$HOME/usr ``` or ``` alias ip4 "python2.4 $HOME/usr/bin/ipython" alias ip5 "python2.5 $HOME/usr/bin/ipython" ``` [fyi](https://github.com/ipython/ipython/wiki/Frequently-asked-questions#q-running-ipython-again...
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
I find the simplest way to specify which python version to use is to explicitly call the ipython script using that version. To do this, you may need to know the path to the ipython script, which you can find by running `which ipython`. Then simply run `python <path-to-ipython>` to start ipython.
You can just: ``` $ python2.4 setup.py install --prefix=$HOME/usr $ python2.5 setup.py install --prefix=$HOME/usr ``` or ``` alias ip4 "python2.4 $HOME/usr/bin/ipython" alias ip5 "python2.5 $HOME/usr/bin/ipython" ``` [fyi](https://github.com/ipython/ipython/wiki/Frequently-asked-questions#q-running-ipython-again...
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
I'm using Ubuntu 10.10 and there's only on ipython installed. (There's also only one python available, but I got an older version with [the deadsnakes ppa](https://launchpad.net/~fkrull/+archive/deadsnakes).) To get ipython2.5, I installed ipython from your virtualenv: ``` virtualenv --python=/usr/bin/python2.5 proje...
Actually you can run the ipython with the python version you like: ``` python2.7 ipython python3 ipython ``` This is easiest solution for me and avoids virtual env setup for one-shot trials.
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
Ok, I answer my own question : I'm dumb :-) ``` ls /usr/bin/ipython* /usr/bin/ipython /usr/bin/ipython2.4 /usr/bin/ipython2.5 ``` Now it's built-in...
I find the simplest way to specify which python version to use is to explicitly call the ipython script using that version. To do this, you may need to know the path to the ipython script, which you can find by running `which ipython`. Then simply run `python <path-to-ipython>` to start ipython.
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
I'm using Ubuntu 10.10 and there's only on ipython installed. (There's also only one python available, but I got an older version with [the deadsnakes ppa](https://launchpad.net/~fkrull/+archive/deadsnakes).) To get ipython2.5, I installed ipython from your virtualenv: ``` virtualenv --python=/usr/bin/python2.5 proje...
I find the simplest way to specify which python version to use is to explicitly call the ipython script using that version. To do this, you may need to know the path to the ipython script, which you can find by running `which ipython`. Then simply run `python <path-to-ipython>` to start ipython.
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
I'm using Ubuntu 10.10 and there's only on ipython installed. (There's also only one python available, but I got an older version with [the deadsnakes ppa](https://launchpad.net/~fkrull/+archive/deadsnakes).) To get ipython2.5, I installed ipython from your virtualenv: ``` virtualenv --python=/usr/bin/python2.5 proje...
To complement on @Peter's answer, I might add that the ipython "executable" you run are simply python script that launch the ipython shell. So a solution that worked for me was to change the python version that runs that script: ```bash $ cp ipython ipython3 $ nano ipython3 ``` Here is what the script looks like: `...
308,254
I am running an Ubuntu 8.10, using Python 2.5 out of the box. This is fine from the system point of view, but I need Python2.4 since I dev on Zope / Plone. Well, installing python2.4 is no challenge, but I can't find a (clean) way to make iPython use it : no option in the man nor in the config file. Before, there was...
2008/11/21
[ "https://Stackoverflow.com/questions/308254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9951/" ]
Ok, I answer my own question : I'm dumb :-) ``` ls /usr/bin/ipython* /usr/bin/ipython /usr/bin/ipython2.4 /usr/bin/ipython2.5 ``` Now it's built-in...
You can just: ``` $ python2.4 setup.py install --prefix=$HOME/usr $ python2.5 setup.py install --prefix=$HOME/usr ``` or ``` alias ip4 "python2.4 $HOME/usr/bin/ipython" alias ip5 "python2.5 $HOME/usr/bin/ipython" ``` [fyi](https://github.com/ipython/ipython/wiki/Frequently-asked-questions#q-running-ipython-again...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
I was also getting this error on a fresh install of XAMPP. For those not comfortable with the command line, there is another way. Based on the advice above (thank you), I used my old standard "Easy Find" to locate the latest version of my.cnf. Upon opening the file in an editor I discovered that the socket file was ...
If you have installed mysql through homebrew, simple `brew services restart mysql` may help.
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
First of all I suggest you to use homebrew to install any third part libraries or tools on your mac. Have a look to : [Link](https://brew.sh/) Otherwise for your problem you can search where is the mysql socket on your mac and then symlink it to /tmp. In your terminal try something like : ``` locate mysql | grep soc...
I am going to throw in my two cents here because I had this problem too but my circumstances are abnormal for most. My system had a blended install of Zend Server CE and XAMPP. I am running Mac OS X. And I decided to remove Zend from my system because it was being a pain in my butt. Upon removing Zend, since both were...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
First of all I suggest you to use homebrew to install any third part libraries or tools on your mac. Have a look to : [Link](https://brew.sh/) Otherwise for your problem you can search where is the mysql socket on your mac and then symlink it to /tmp. In your terminal try something like : ``` locate mysql | grep soc...
I was getting some similar error and ended up here. I am using OSX 10.9.5. This solved my problems (hope it helps someone). 1) sudo mkdir /var/mysql 2) sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock More informations: <http://glidingphenomena.blogspot.com.br/2010/03/fixing-warning-mysqlconnect-cant.html> ...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
I was getting some similar error and ended up here. I am using OSX 10.9.5. This solved my problems (hope it helps someone). 1) sudo mkdir /var/mysql 2) sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock More informations: <http://glidingphenomena.blogspot.com.br/2010/03/fixing-warning-mysqlconnect-cant.html> ...
Ok, I just spent a couple hours struggling with this same problem. I had installed the dmg file for MySql 5.5.20 (64bit) for osx 10.6 on my iMac with OSX 10.7.2 - and the /tmp/mysql.sock was missing! The answer turned out to be simply install the MySQLStartupItem.pkg that comes with the dmg file and restart the system...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
I was getting some similar error and ended up here. I am using OSX 10.9.5. This solved my problems (hope it helps someone). 1) sudo mkdir /var/mysql 2) sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock More informations: <http://glidingphenomena.blogspot.com.br/2010/03/fixing-warning-mysqlconnect-cant.html> ...
Found the solution: I had the same issue and I did a lot of searches but couldn't solve the issue until I looked at my MySql config file. In my config file socket was in line 21 and the path was "/Applications/AMPPS/var/mysql.sock" In Ampps application click on MySql tab and then click on configuration button. ...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
I am going to throw in my two cents here because I had this problem too but my circumstances are abnormal for most. My system had a blended install of Zend Server CE and XAMPP. I am running Mac OS X. And I decided to remove Zend from my system because it was being a pain in my butt. Upon removing Zend, since both were...
Found the solution: I had the same issue and I did a lot of searches but couldn't solve the issue until I looked at my MySql config file. In my config file socket was in line 21 and the path was "/Applications/AMPPS/var/mysql.sock" In Ampps application click on MySql tab and then click on configuration button. ...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
First of all I suggest you to use homebrew to install any third part libraries or tools on your mac. Have a look to : [Link](https://brew.sh/) Otherwise for your problem you can search where is the mysql socket on your mac and then symlink it to /tmp. In your terminal try something like : ``` locate mysql | grep soc...
Ok, I just spent a couple hours struggling with this same problem. I had installed the dmg file for MySql 5.5.20 (64bit) for osx 10.6 on my iMac with OSX 10.7.2 - and the /tmp/mysql.sock was missing! The answer turned out to be simply install the MySQLStartupItem.pkg that comes with the dmg file and restart the system...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
First of all I suggest you to use homebrew to install any third part libraries or tools on your mac. Have a look to : [Link](https://brew.sh/) Otherwise for your problem you can search where is the mysql socket on your mac and then symlink it to /tmp. In your terminal try something like : ``` locate mysql | grep soc...
I was also getting this error on a fresh install of XAMPP. For those not comfortable with the command line, there is another way. Based on the advice above (thank you), I used my old standard "Easy Find" to locate the latest version of my.cnf. Upon opening the file in an editor I discovered that the socket file was ...
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
Ok, I just spent a couple hours struggling with this same problem. I had installed the dmg file for MySql 5.5.20 (64bit) for osx 10.6 on my iMac with OSX 10.7.2 - and the /tmp/mysql.sock was missing! The answer turned out to be simply install the MySQLStartupItem.pkg that comes with the dmg file and restart the system...
If you have installed mysql through homebrew, simple `brew services restart mysql` may help.
5,784,791
I installed MySQL on my Mac OS 10.6 about a week ago, and, after some playing around, got it to work just fine. It integrated with python MySQLdb and I also got Sequel Pro to connect to the database. However, php wouldn't access the server. Even after I added a php.ini file to /etc/ and directed it toward the same sock...
2011/04/26
[ "https://Stackoverflow.com/questions/5784791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/321838/" ]
I was getting some similar error and ended up here. I am using OSX 10.9.5. This solved my problems (hope it helps someone). 1) sudo mkdir /var/mysql 2) sudo ln -s /private/tmp/mysql.sock /var/mysql/mysql.sock More informations: <http://glidingphenomena.blogspot.com.br/2010/03/fixing-warning-mysqlconnect-cant.html> ...
I was also getting this error on a fresh install of XAMPP. For those not comfortable with the command line, there is another way. Based on the advice above (thank you), I used my old standard "Easy Find" to locate the latest version of my.cnf. Upon opening the file in an editor I discovered that the socket file was ...
61,261,306
I recently started exploring VS Code for developing Python code and I’m running into an issue when I try to import a module from a subfolder. The exact same code runs perfectly when I execute it in a Jupyter notebook (the subfolders contain the `__init__.py` files etc.) I believe I followed the instructions for setting...
2020/04/16
[ "https://Stackoverflow.com/questions/61261306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1952633/" ]
Stefan‘s method worked for me. Taking as example filesystem: workspaceFolder/folder/subfolder1/subfolder2/bar.py I wasn't able to import subfolders like: `from folder.subfolder1.subfolder2 import bar` It said: `ModuleNotFoundError: No module named 'folder'` I added to .vscode/settings.json the following: ``` "termi...
I think I finally figured out the answer myself: The integrated terminal does not scan the `PYTHONPATH` from the `.env`-file. When running the file in an integrated window, the `PYTHONPATH` is correctly taken from `.env`, however. So in order to run my script in the terminal I had to add the `terminal.integrated.env.*`...
61,279,933
In python, I run this simple code: ```py print('number is %.15f'%1.6) ``` which works fine (Output: `number is 1.600000000000000`), but when I take the decimal places to `16>=`, I start getting random numbers at the end. For example: ```py print('number is %.16f'%1.6) ``` Output: `number is 1.6000000000000001` an...
2020/04/17
[ "https://Stackoverflow.com/questions/61279933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13159127/" ]
Work-around 1. Open Hyper-V Manager under Windows Administrative Tools 2. Note DockerDesktopVM is not running under Virtual Machines 3. Under the Actions pane, click Stop Service, then click Start Service 4. Restart Docker Desktop Its worked for me
Make sure that the VT-X virtualization is enabled in your BIOS
61,279,933
In python, I run this simple code: ```py print('number is %.15f'%1.6) ``` which works fine (Output: `number is 1.600000000000000`), but when I take the decimal places to `16>=`, I start getting random numbers at the end. For example: ```py print('number is %.16f'%1.6) ``` Output: `number is 1.6000000000000001` an...
2020/04/17
[ "https://Stackoverflow.com/questions/61279933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13159127/" ]
I was facing the same issue I resolved this issue following below steps. If you are able to run Windows container that means issue is with Hyper-V 1. Enable hyper on VM by - [![enter image description here](https://i.stack.imgur.com/mlaQh.png)](https://i.stack.imgur.com/mlaQh.png) 2. We must enable hardware virtulizat...
Make sure that the VT-X virtualization is enabled in your BIOS
61,279,933
In python, I run this simple code: ```py print('number is %.15f'%1.6) ``` which works fine (Output: `number is 1.600000000000000`), but when I take the decimal places to `16>=`, I start getting random numbers at the end. For example: ```py print('number is %.16f'%1.6) ``` Output: `number is 1.6000000000000001` an...
2020/04/17
[ "https://Stackoverflow.com/questions/61279933", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13159127/" ]
Work-around 1. Open Hyper-V Manager under Windows Administrative Tools 2. Note DockerDesktopVM is not running under Virtual Machines 3. Under the Actions pane, click Stop Service, then click Start Service 4. Restart Docker Desktop Its worked for me
I was facing the same issue I resolved this issue following below steps. If you are able to run Windows container that means issue is with Hyper-V 1. Enable hyper on VM by - [![enter image description here](https://i.stack.imgur.com/mlaQh.png)](https://i.stack.imgur.com/mlaQh.png) 2. We must enable hardware virtulizat...
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I did some modification to the SMNALLY's code so it can run in Python 3.5.2. This is my result: ```py #Import the following library to make use of the DispatchEx to run the macro import win32com.client as wincl def runMacro(): if os.path.exists("C:\\Users\\Dev\\Desktop\\Development\\completed_app...
I suspect you haven't authorize your Excel installation to run macro from an automated Excel. It is a security protection by default at installation. To change this: 1. File > Options > Trust Center 2. Click on Trust Center Settings... button 3. Macro Settings > Check Enable all macros
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I suspect you haven't authorize your Excel installation to run macro from an automated Excel. It is a security protection by default at installation. To change this: 1. File > Options > Trust Center 2. Click on Trust Center Settings... button 3. Macro Settings > Check Enable all macros
For Python 3.7 or later,(2018-10-10), I have to combine both @Alejandro BR and SMNALLY's answer, coz @Alejandro forget to define wincl. ``` import os, os.path import win32com.client if os.path.exists('C:/Users/jz/Desktop/test.xlsm'): excel_macro = win32com.client.DispatchEx("Excel.Application") # DispatchEx is req...
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I suspect you haven't authorize your Excel installation to run macro from an automated Excel. It is a security protection by default at installation. To change this: 1. File > Options > Trust Center 2. Click on Trust Center Settings... button 3. Macro Settings > Check Enable all macros
A variation on SMNALLY's code that doesn't quit Excel if you already have it open: ```py import os, os.path import win32com.client if os.path.exists("excelsheet.xlsm"): xl=win32com.client.Dispatch("Excel.Application") wb = xl.Workbooks.Open(os.path.abspath("excelsheet.xlsm"), ReadOnly=1) #create a workbook ob...
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I would expect the error is to do with the macro you're calling, try the following bit of code: ### Code ``` import os, os.path import win32com.client if os.path.exists("excelsheet.xlsm"): xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(os.path.abspath("excelsheet.xlsm"), ReadOnly=1) x...
Just a quick note with a xlsm with spaces. ``` file = 'file with spaces.xlsm' excel_macro.Application.Run('\'' + file + '\'' + "!Module1.Macro1") ```
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I would expect the error is to do with the macro you're calling, try the following bit of code: ### Code ``` import os, os.path import win32com.client if os.path.exists("excelsheet.xlsm"): xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(os.path.abspath("excelsheet.xlsm"), ReadOnly=1) x...
I tried the win32com way and xlwings way but I didn't get any luck. I use PyCharm and didn't see the .WorkBook option in the autocompletion for win32com. I got the -2147352567 error when I tried to pass a workbook as variable. Then, I found a work around using vba shell to run my Python script. Write something on the...
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I did some modification to the SMNALLY's code so it can run in Python 3.5.2. This is my result: ```py #Import the following library to make use of the DispatchEx to run the macro import win32com.client as wincl def runMacro(): if os.path.exists("C:\\Users\\Dev\\Desktop\\Development\\completed_app...
A variation on SMNALLY's code that doesn't quit Excel if you already have it open: ```py import os, os.path import win32com.client if os.path.exists("excelsheet.xlsm"): xl=win32com.client.Dispatch("Excel.Application") wb = xl.Workbooks.Open(os.path.abspath("excelsheet.xlsm"), ReadOnly=1) #create a workbook ob...
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I did some modification to the SMNALLY's code so it can run in Python 3.5.2. This is my result: ```py #Import the following library to make use of the DispatchEx to run the macro import win32com.client as wincl def runMacro(): if os.path.exists("C:\\Users\\Dev\\Desktop\\Development\\completed_app...
For Python 3.7 or later,(2018-10-10), I have to combine both @Alejandro BR and SMNALLY's answer, coz @Alejandro forget to define wincl. ``` import os, os.path import win32com.client if os.path.exists('C:/Users/jz/Desktop/test.xlsm'): excel_macro = win32com.client.DispatchEx("Excel.Application") # DispatchEx is req...
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I would expect the error is to do with the macro you're calling, try the following bit of code: ### Code ``` import os, os.path import win32com.client if os.path.exists("excelsheet.xlsm"): xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(os.path.abspath("excelsheet.xlsm"), ReadOnly=1) x...
I suspect you haven't authorize your Excel installation to run macro from an automated Excel. It is a security protection by default at installation. To change this: 1. File > Options > Trust Center 2. Click on Trust Center Settings... button 3. Macro Settings > Check Enable all macros
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
I did some modification to the SMNALLY's code so it can run in Python 3.5.2. This is my result: ```py #Import the following library to make use of the DispatchEx to run the macro import win32com.client as wincl def runMacro(): if os.path.exists("C:\\Users\\Dev\\Desktop\\Development\\completed_app...
I tried the win32com way and xlwings way but I didn't get any luck. I use PyCharm and didn't see the .WorkBook option in the autocompletion for win32com. I got the -2147352567 error when I tried to pass a workbook as variable. Then, I found a work around using vba shell to run my Python script. Write something on the...
19,616,205
I'm trying to run a macro via python but I'm not sure how to get it working... I've got the following code so far, but it's not working. ``` import win32com.client xl=win32com.client.Dispatch("Excel.Application") xl.Workbooks.Open(Filename="C:\test.xlsm",ReadOnly=1) xl.Application.Run("macrohere") xl.Workbooks(1).Clo...
2013/10/27
[ "https://Stackoverflow.com/questions/19616205", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2487602/" ]
A variation on SMNALLY's code that doesn't quit Excel if you already have it open: ```py import os, os.path import win32com.client if os.path.exists("excelsheet.xlsm"): xl=win32com.client.Dispatch("Excel.Application") wb = xl.Workbooks.Open(os.path.abspath("excelsheet.xlsm"), ReadOnly=1) #create a workbook ob...
I tried the win32com way and xlwings way but I didn't get any luck. I use PyCharm and didn't see the .WorkBook option in the autocompletion for win32com. I got the -2147352567 error when I tried to pass a workbook as variable. Then, I found a work around using vba shell to run my Python script. Write something on the...
73,111,056
I am fairly new at writing code and trying to teach myself python and pyspark based on searching the web for answers to my problems. I am trying to build a historical record set based on daily changes. I periodically have to bump the semantic version, but do not want to lose my already collected historical data. If the...
2022/07/25
[ "https://Stackoverflow.com/questions/73111056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19213719/" ]
You use the 'IncrementalTransformContext' of the transform to determine whether it is running incrementally. This can be seen in the code below. ``` @incremental() @transform( x=Output(), y=Input(), z=Input(), ) def compute(ctx, x, y, z): if ctx.is_incremental: ## Some Code else: #...
In an incremental transform, there is a boolean flag property called 'is\_incremental' in the [incremental transform context object](https://www.palantir.com/docs/foundry/transforms-python/incremental-reference/#incrementaltransformcontext). Therefore, I think you can do a single incremental transform definition and b...
4,827,244
I'm trying to get an implementation of github flavored markdown working in python, with no luck... I don't have much in the way of regex skills. Here's the ruby code from [github](https://github.com/github/github-flavored-markdown/blob/gh-pages/code.rb#L17): ``` # in very clear cases, let newlines become <br /> tags...
2011/01/28
[ "https://Stackoverflow.com/questions/4827244", "https://Stackoverflow.com", "https://Stackoverflow.com/users/73831/" ]
That Ruby version has **multiline modifier** in the regex, so you need to do the same in python: ``` def newline_callback(matchobj): return re.sub(re.compile(r'^(.+)$', re.M),r'\1 ',matchobj.group(0)) text = re.sub(re.compile(r'(\A|^$\n)(^\w[^\n]*\n)(^\w[^\n]*$)+', re.M), newline_callback, text) ``` So th...
``` return re.sub(r'^(.+)$',r'\1 ',matchobj.group(0)) ^^^--------------------------- you forgot this. ```
3,115,448
this html is [here](https://mail.google.com/mail/?ui=2&ik=a0b1e46c9c&view=att&th=1296be43b8e3bbd9&attid=0.1&disp=inline&zw) : ``` <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body> <div bgcolor="#48486c"> ...
2010/06/25
[ "https://Stackoverflow.com/questions/3115448", "https://Stackoverflow.com", "https://Stackoverflow.com/users/234322/" ]
[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) gets you almost all the way there: ``` >>> import BeautifulSoup >>> f = open('a.html') >>> soup = BeautifulSoup.BeautifulSoup(f) >>> f.close() >>> g = open('a.xml', 'w') >>> print >> g, soup.prettify() >>> g.close() ``` This closes all tags properly. The...
lxml works well: ``` from lxml import html, etree doc = html.fromstring(open('a.html').read()) out = open('a.xhtml', 'wb') out.write(etree.tostring(doc)) ```
3,115,448
this html is [here](https://mail.google.com/mail/?ui=2&ik=a0b1e46c9c&view=att&th=1296be43b8e3bbd9&attid=0.1&disp=inline&zw) : ``` <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body> <div bgcolor="#48486c"> ...
2010/06/25
[ "https://Stackoverflow.com/questions/3115448", "https://Stackoverflow.com", "https://Stackoverflow.com/users/234322/" ]
[BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/) gets you almost all the way there: ``` >>> import BeautifulSoup >>> f = open('a.html') >>> soup = BeautifulSoup.BeautifulSoup(f) >>> f.close() >>> g = open('a.xml', 'w') >>> print >> g, soup.prettify() >>> g.close() ``` This closes all tags properly. The...
To piggyback off @Alex Martelli, as of `Python 2.5`, there is an xml module that comes baked into the standard library: <https://docs.python.org/3.6/library/xml.html> You could strip all HTML tags off, then format into xml and use the baked in XML library instead of bringing in another dependency. This is only advisa...
3,115,448
this html is [here](https://mail.google.com/mail/?ui=2&ik=a0b1e46c9c&view=att&th=1296be43b8e3bbd9&attid=0.1&disp=inline&zw) : ``` <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><META http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body> <div bgcolor="#48486c"> ...
2010/06/25
[ "https://Stackoverflow.com/questions/3115448", "https://Stackoverflow.com", "https://Stackoverflow.com/users/234322/" ]
lxml works well: ``` from lxml import html, etree doc = html.fromstring(open('a.html').read()) out = open('a.xhtml', 'wb') out.write(etree.tostring(doc)) ```
To piggyback off @Alex Martelli, as of `Python 2.5`, there is an xml module that comes baked into the standard library: <https://docs.python.org/3.6/library/xml.html> You could strip all HTML tags off, then format into xml and use the baked in XML library instead of bringing in another dependency. This is only advisa...
6,987,413
I started using the protocol buffer library, but noticed that it was using huge amounts of memory. pympler.asizeof shows that a single one of my objects is about 76k! Basically, it contains a few strings, some numbers, and some enums, and some optional lists of same. If I were writing the same thing as a C-struct, I wo...
2011/08/08
[ "https://Stackoverflow.com/questions/6987413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/189456/" ]
Object instances have a bigger memory footprint in python than in compiled languages. For example, the following code, which creates very simple classes mimicking your proto displays 1440: ``` class A: def __init__(self): self.a = 0.0 class B: def __init__(self): self.b = 0.0 class C: def __init__(self...
Edit: This isn't likely your actual issue here, but we've just been experiencing a 45MB protobuf message taking > 4GB ram when decoding. It appears to be this: <https://github.com/google/protobuf/issues/156> which was known about in protobuf 2.6 and a fix was only merged onto master march 7 this year: <https://github...
69,495,394
input file.csv ``` ['NE,PORT,EVENT,TIME,VALUE', 'NODE,13,MAX,2021-08-30 09:15:00+01:00 DST,-10.9', 'NODE,13,MIN,2021-08-30 09:15:00+01:00 DST,-11.0', 'NODE,13,CUR,2021-08-30 09:15:00+01:00 DST,-10.9', 'NODE,13,MAX,2021-08-30 10:30:00+01:00 DST,-12.9', 'NODE,13,MIN,2021-08-30 10:30:00+01:00 DST,-10.0', 'NODE,13,CU...
2021/10/08
[ "https://Stackoverflow.com/questions/69495394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17106118/" ]
One way to do this is by creating a pivot table. ``` csv = ['NE,PORT,EVENT,TIME,VALUE', 'NODE,13,MAX,2021-08-30 09:15:00+01:00 DST,-10.9', 'NODE,13,MIN,2021-08-30 09:15:00+01:00 DST,-11.0', 'NODE,13,CUR,2021-08-30 09:15:00+01:00 DST,-10.9', 'NODE,13,MAX,2021-08-30 10:30:00+01:00 DST,-12.9', 'NODE,13,MIN,2021-08-30...
i'll correct just your first step. your logic was good, but there was a lot of confusion due to too many lists ``` for lista in check: lista=lista.split(",") lista.extend(['MAX','MIN','CUR']) if lista[2]==('MAX'): lista[5] = lista[4] elif lista[2]==('MIN'): lista[6] = lista[4] elif ...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
Basically, it simplifies any loop that uses a boolean flag like this: ``` found = False # <-- initialize boolean for divisor in range(2, n): if n % divisor == 0: found = True # <-- update boolean break # optional, but continuing would be a waste of time if found: ...
Without using `break`, `else` blocks have no benefit for `for` and `while` statements. The following two examples are equivalent: ``` for x in range(10): pass else: print "else" for x in range(10): pass print "else" ``` The only reason for using `else` with `for` or `while` is to do something after the loop i...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
A use case of the `else` clause of loops is breaking out of nested loops: ``` while True: for item in iterable: if condition: break suite else: continue break ``` It avoids repeating conditions: ``` while not condition: for item in iterable: if condition: ...
Here you go: ``` a = ('y','a','y') for x in a: print x, else: print '!' ``` It's for the caboose. edit: ``` # What happens if we add the ! to a list? def side_effect(your_list): your_list.extend('!') for x in your_list: print x, claimant = ['A',' ','g','u','r','u'] side_effect(claimant) print claiman...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
What could be more pythonic than PyPy? Look at what I discovered starting at line 284 in ctypes\_configure/configure.py: ``` for i in range(0, info['size'] - csize + 1, info['align']): if layout[i:i+csize] == [None] * csize: layout_addfield(layout, i, ctype, '_alignment') break ...
Without using `break`, `else` blocks have no benefit for `for` and `while` statements. The following two examples are equivalent: ``` for x in range(10): pass else: print "else" for x in range(10): pass print "else" ``` The only reason for using `else` with `for` or `while` is to do something after the loop i...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
What could be more pythonic than PyPy? Look at what I discovered starting at line 284 in ctypes\_configure/configure.py: ``` for i in range(0, info['size'] - csize + 1, info['align']): if layout[i:i+csize] == [None] * csize: layout_addfield(layout, i, ctype, '_alignment') break ...
Here you go: ``` a = ('y','a','y') for x in a: print x, else: print '!' ``` It's for the caboose. edit: ``` # What happens if we add the ! to a list? def side_effect(your_list): your_list.extend('!') for x in your_list: print x, claimant = ['A',' ','g','u','r','u'] side_effect(claimant) print claiman...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
If you have a for loop you don't really have any condition statement. So break is your choice if you like to abort and then else can serve perfectly to handle the case where you were not happy. ``` for fruit in basket: if fruit.kind in ['Orange', 'Apple']: fruit.eat() break else: print 'The basket ...
I was introduced to a wonderful idiom in which you can use a `for`/`break`/`else` scheme with an iterator to save both time and LOC. The example at hand was searching for the candidate for an incompletely qualified path. If you care to see the original context, please see [the original question](https://stackoverflow.c...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
If you have a for loop you don't really have any condition statement. So break is your choice if you like to abort and then else can serve perfectly to handle the case where you were not happy. ``` for fruit in basket: if fruit.kind in ['Orange', 'Apple']: fruit.eat() break else: print 'The basket ...
Here you go: ``` a = ('y','a','y') for x in a: print x, else: print '!' ``` It's for the caboose. edit: ``` # What happens if we add the ! to a list? def side_effect(your_list): your_list.extend('!') for x in your_list: print x, claimant = ['A',' ','g','u','r','u'] side_effect(claimant) print claiman...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
I was introduced to a wonderful idiom in which you can use a `for`/`break`/`else` scheme with an iterator to save both time and LOC. The example at hand was searching for the candidate for an incompletely qualified path. If you care to see the original context, please see [the original question](https://stackoverflow.c...
A use case of the `else` clause of loops is breaking out of nested loops: ``` while True: for item in iterable: if condition: break suite else: continue break ``` It avoids repeating conditions: ``` while not condition: for item in iterable: if condition: ...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
What could be more pythonic than PyPy? Look at what I discovered starting at line 284 in ctypes\_configure/configure.py: ``` for i in range(0, info['size'] - csize + 1, info['align']): if layout[i:i+csize] == [None] * csize: layout_addfield(layout, i, ctype, '_alignment') break ...
Perhaps the best answer comes from the official Python tutorial: [break and continue Statements, and else Clauses on Loops](http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops): > > *Loop statements may have an else > clause; it is executed when the loop > termi...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
Perhaps the best answer comes from the official Python tutorial: [break and continue Statements, and else Clauses on Loops](http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops): > > *Loop statements may have an else > clause; it is executed when the loop > termi...
A use case of the `else` clause of loops is breaking out of nested loops: ``` while True: for item in iterable: if condition: break suite else: continue break ``` It avoids repeating conditions: ``` while not condition: for item in iterable: if condition: ...
685,758
I have hardly ever noticed a python program that uses else in a for loop. I recently used it to perform an action based on the loop variable condition while exiting; as it is in the scope. What is the pythonic way to use an else in a for loop? Are there any notable use cases? And, yea. I dislike using break statemen...
2009/03/26
[ "https://Stackoverflow.com/questions/685758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55562/" ]
If you have a for loop you don't really have any condition statement. So break is your choice if you like to abort and then else can serve perfectly to handle the case where you were not happy. ``` for fruit in basket: if fruit.kind in ['Orange', 'Apple']: fruit.eat() break else: print 'The basket ...
Perhaps the best answer comes from the official Python tutorial: [break and continue Statements, and else Clauses on Loops](http://docs.python.org/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops): > > *Loop statements may have an else > clause; it is executed when the loop > termi...
32,043,990
I'm trying to get the `SPF records` of a `domains` and the domains are read from a file.When i am trying to get the spf contents and write it to a file and the code gives me the results of last domain got from input file. ``` Example `Input_Domains.txt` blah.com box.com marketo.com ``` The output,I get is only for...
2015/08/17
[ "https://Stackoverflow.com/questions/32043990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5093018/" ]
It is because you are rewriting `full_spf` all the time so only last value is stored ``` with open('Input_Domains.txt','r') as f: for line in f: full_spf=getspf(line.strip()) ``` **Modification:** ``` with open('Input_Domains.txt','r') as f: full_spf="" for line in f: full_spf+=getspf(li...
Try using [a generator expression](https://wiki.python.org/moin/Generators) inside your `with` block, instead of a regular `for` loop: ``` full_spf = '\n'.join(getspf(line.strip()) for line in f) ``` This will grab all the lines at once, do your custom `getspf` operations to them, and then join them with newlines be...
25,927,804
Hey guys For my school project I need to web scrape slideshare.net for page views using python. However, it wont let me scrape the page views of the user name (which the professor specifically told us to scrape) for example if I go to slideshare.net/Username on the bottom there will be a page view counter when i go int...
2014/09/19
[ "https://Stackoverflow.com/questions/25927804", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4057203/" ]
You have a space at the start of your regex string, so it will only match if there's (at least) one space before the `<span`... So instead of `regex = ' <span class="noWrap">(.+?)</span>'` try `regex = '<span class="noWrap">(.+?)</span>'` or even better `regex = r'<span class="noWrap">\s*(.+?)\s*</span>'` Raw s...
Although this in not an technically an answer you will need to change your regular expression. I suggest you look at the python regex chapters. What I will tell you is that your line ``` regex = ' <span class="noWrap">(.+?)</span>' ``` will not match what you are after based on the output of the webpage since there...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Create an instance of `customLogger` in your log module and use it as a singleton - just use the imported instance, rather than the class.
You can just pass it a string with a common sub-string before the first period. The parts of the string separated by the period (".") can be used for different classes / modules / files / etc. Like so (specifically the `logger = logging.getLogger(loggerName)` part): ``` def getLogger(name, logdir=LOGDIR_DEFAULT, level...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Use [`logging.getLogger(name)`](https://docs.python.org/3/library/logging.html#logging.getLogger) to create a named global logger. **main.py** ``` import log logger = log.setup_custom_logger('root') logger.debug('main message') import submodule ``` **log.py** ``` import logging def setup_custom_logger(name): ...
Create an instance of `customLogger` in your log module and use it as a singleton - just use the imported instance, rather than the class.
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Since I haven't found a satisfactory answer, I would like to elaborate on the answer to the question a little bit in order to give some insight into the workings and intents of the `logging` library, that comes with Python's standard library. In contrast to the approach of the OP (original poster) the library clearly...
Create an instance of `customLogger` in your log module and use it as a singleton - just use the imported instance, rather than the class.
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Create an instance of `customLogger` in your log module and use it as a singleton - just use the imported instance, rather than the class.
The python logging module is already good enough as global logger, you might simply looking for this: **main.py** ``` import logging logging.basicConfig(level = logging.DEBUG,format = '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s') ``` Put the codes above into your executing script, then you can us...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Use [`logging.getLogger(name)`](https://docs.python.org/3/library/logging.html#logging.getLogger) to create a named global logger. **main.py** ``` import log logger = log.setup_custom_logger('root') logger.debug('main message') import submodule ``` **log.py** ``` import logging def setup_custom_logger(name): ...
You can just pass it a string with a common sub-string before the first period. The parts of the string separated by the period (".") can be used for different classes / modules / files / etc. Like so (specifically the `logger = logging.getLogger(loggerName)` part): ``` def getLogger(name, logdir=LOGDIR_DEFAULT, level...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Since I haven't found a satisfactory answer, I would like to elaborate on the answer to the question a little bit in order to give some insight into the workings and intents of the `logging` library, that comes with Python's standard library. In contrast to the approach of the OP (original poster) the library clearly...
You can just pass it a string with a common sub-string before the first period. The parts of the string separated by the period (".") can be used for different classes / modules / files / etc. Like so (specifically the `logger = logging.getLogger(loggerName)` part): ``` def getLogger(name, logdir=LOGDIR_DEFAULT, level...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
The python logging module is already good enough as global logger, you might simply looking for this: **main.py** ``` import logging logging.basicConfig(level = logging.DEBUG,format = '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s') ``` Put the codes above into your executing script, then you can us...
You can just pass it a string with a common sub-string before the first period. The parts of the string separated by the period (".") can be used for different classes / modules / files / etc. Like so (specifically the `logger = logging.getLogger(loggerName)` part): ``` def getLogger(name, logdir=LOGDIR_DEFAULT, level...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Use [`logging.getLogger(name)`](https://docs.python.org/3/library/logging.html#logging.getLogger) to create a named global logger. **main.py** ``` import log logger = log.setup_custom_logger('root') logger.debug('main message') import submodule ``` **log.py** ``` import logging def setup_custom_logger(name): ...
Since I haven't found a satisfactory answer, I would like to elaborate on the answer to the question a little bit in order to give some insight into the workings and intents of the `logging` library, that comes with Python's standard library. In contrast to the approach of the OP (original poster) the library clearly...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Use [`logging.getLogger(name)`](https://docs.python.org/3/library/logging.html#logging.getLogger) to create a named global logger. **main.py** ``` import log logger = log.setup_custom_logger('root') logger.debug('main message') import submodule ``` **log.py** ``` import logging def setup_custom_logger(name): ...
The python logging module is already good enough as global logger, you might simply looking for this: **main.py** ``` import logging logging.basicConfig(level = logging.DEBUG,format = '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s') ``` Put the codes above into your executing script, then you can us...
7,621,897
I was wondering how to implement a global logger that could be used everywhere with your own settings: I currently have a custom logger class: ``` class customLogger(logging.Logger): ... ``` The class is in a separate file with some formatters and other stuff. The logger works perfectly on its own. I import thi...
2011/10/01
[ "https://Stackoverflow.com/questions/7621897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/815382/" ]
Since I haven't found a satisfactory answer, I would like to elaborate on the answer to the question a little bit in order to give some insight into the workings and intents of the `logging` library, that comes with Python's standard library. In contrast to the approach of the OP (original poster) the library clearly...
The python logging module is already good enough as global logger, you might simply looking for this: **main.py** ``` import logging logging.basicConfig(level = logging.DEBUG,format = '[%(asctime)s] %(levelname)s [%(name)s:%(lineno)s] %(message)s') ``` Put the codes above into your executing script, then you can us...
69,410,508
I wanted to save all the text which I enter in the listbox. "my\_list" is the listbox over here. But when I save my file, I get the output in the form of a tuple, as shown below: ``` ("Some","Random","Values") ``` Below is the python code. I have added comments to it. The add\_items function adds data into the entry...
2021/10/01
[ "https://Stackoverflow.com/questions/69410508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16781901/" ]
The main part is that `listbox.get(first, last)` returns a tuple so you could use `.join` string method to create a string where each item in the tuple is separated by the given string: ```py '\n'.join(listbox.get('0', 'end')) ``` Complete example: ```py from tkinter import Tk, Entry, Listbox, Button def add_item(...
This is a very simple task. Where you are saving the file, write this code: ``` newlist = [] for item in mylist.get(0, END): newlist.append(item) f = open(file, 'w') for line in newlist: f.write(line+'\n') f.close() ``` To know more about file saving in tkinter or to make it much easier, you can check my txtopp rep...
60,838,550
I've written a script in python using selenium to log in to a website and then go on to the target page in order to upload a pdf file. The script can log in successfully but throws `element not interactable` error when it comes to upload the pdf file. This is the [landing\_page](https://jobs.allianz.com/sap/bc/bsp/sap/...
2020/03/24
[ "https://Stackoverflow.com/questions/60838550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10568531/" ]
Please refer below solution to avoid your exception, ``` from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait as Wait f...
Try this script , it upload document on both pages ``` from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC landing_page = 'https://jobs.allianz.com/sap/bc/bsp/sap/zhcmx_erc_u...
16,505,752
I collected some tweets through twitter api. Then I counted the words using `split(' ')` in python. However, some words appear like this: ``` correct! correct. ,correct blah" ... ``` So how can I format the tweets without punctuation? Or maybe I should try another way to `split` tweets? Thanks.
2013/05/12
[ "https://Stackoverflow.com/questions/16505752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/975222/" ]
You can do the split on multiple characters using `re.split`... ``` from string import punctuation import re puncrx = re.compile(r'[{}\s]'.format(re.escape(punctuation))) print filter(None, puncrx.split(your_tweet)) ``` Or, just find words that contain certain contiguous characters: ``` print re.findall(re.findall...
Try removing the punctuation from the string before doing the split. ``` import string s = "Some nice sentence. This has punctuation!" out = s.translate(string.maketrans("",""), string.punctuation) ``` Then do the `split` on `out`.
16,505,752
I collected some tweets through twitter api. Then I counted the words using `split(' ')` in python. However, some words appear like this: ``` correct! correct. ,correct blah" ... ``` So how can I format the tweets without punctuation? Or maybe I should try another way to `split` tweets? Thanks.
2013/05/12
[ "https://Stackoverflow.com/questions/16505752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/975222/" ]
You can do the split on multiple characters using `re.split`... ``` from string import punctuation import re puncrx = re.compile(r'[{}\s]'.format(re.escape(punctuation))) print filter(None, puncrx.split(your_tweet)) ``` Or, just find words that contain certain contiguous characters: ``` print re.findall(re.findall...
I would advice to clean text from special symbols before splitting it using this code: ``` tweet_object["text"] = re.sub(u'[!?@#$.,#:\u2026]', '', tweet_object["text"]) ``` You would need to import re before using function sub ``` import re ```
56,399,448
I have the following code which sums up values of each key. I am trying to use the list in the reducer since my actual use case is to sample values of each key. I get the error I show below? How do I achieve with a list(or tuple). I always get my data in the form of tensors and need to use tensorflow to achieve the red...
2019/05/31
[ "https://Stackoverflow.com/questions/56399448", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7418127/" ]
What you can do to mock your store is ``` import { store } from './reduxStore'; import sampleFunction from './sampleFunction.js'; jest.mock('./reduxStore') const mockState = { foo: { isGood: true } } // in this point store.getState is going to be mocked store.getState = () => mockState test('sampleFunction retur...
``` import { store } from './reduxStore'; import sampleFunction from './sampleFunction.js'; beforeAll(() => { jest.mock('./reduxStore') const mockState = { foo: { isGood: true } } // making getState as mock function and returning mock value store.getState = jest.fn().mockReturnValue(mockState) }); afterAll(() ...
36,620,656
I am trying to learn how to write a script `control.py`, that runs another script `test.py` in a loop for a certain number of times, in each run, reads its output and halts it if some predefined output is printed (e.g. the text 'stop now'), and the loop continues its iteration (once `test.py` has finished, either on it...
2016/04/14
[ "https://Stackoverflow.com/questions/36620656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You can use subprocess module or also the os.popen ``` os.popen(command[, mode[, bufsize]]) ``` Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. With subprocess I would suggest ``` subpro...
You can use the "subprocess" library for that. ``` import subprocess command = ["python", "test.py", "someargument"] for i in range(n): p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: output = p.stdout.readline() if output == '' and p.poll() is not ...
36,620,656
I am trying to learn how to write a script `control.py`, that runs another script `test.py` in a loop for a certain number of times, in each run, reads its output and halts it if some predefined output is printed (e.g. the text 'stop now'), and the loop continues its iteration (once `test.py` has finished, either on it...
2016/04/14
[ "https://Stackoverflow.com/questions/36620656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What you are hinting at in your comment to Marc Cabos' answer is [Threading](https://docs.python.org/3/library/threading.html) There are several ways Python can use the functionality of other files. If the content of `test.py` can be encapsulated in a function or class, then you can `import` the relevant parts into yo...
You can use the "subprocess" library for that. ``` import subprocess command = ["python", "test.py", "someargument"] for i in range(n): p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) while True: output = p.stdout.readline() if output == '' and p.poll() is not ...
36,620,656
I am trying to learn how to write a script `control.py`, that runs another script `test.py` in a loop for a certain number of times, in each run, reads its output and halts it if some predefined output is printed (e.g. the text 'stop now'), and the loop continues its iteration (once `test.py` has finished, either on it...
2016/04/14
[ "https://Stackoverflow.com/questions/36620656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
You can use subprocess module or also the os.popen ``` os.popen(command[, mode[, bufsize]]) ``` Open a pipe to or from command. The return value is an open file object connected to the pipe, which can be read or written depending on whether mode is 'r' (default) or 'w'. With subprocess I would suggest ``` subpro...
Yes you can use Python to control another program using stdin/stdout, but when using another process output often there is a problem of buffering, in other words the other process doesn't really output anything until it's done. There are even cases in which the output is buffered or not depending on if the program is ...
36,620,656
I am trying to learn how to write a script `control.py`, that runs another script `test.py` in a loop for a certain number of times, in each run, reads its output and halts it if some predefined output is printed (e.g. the text 'stop now'), and the loop continues its iteration (once `test.py` has finished, either on it...
2016/04/14
[ "https://Stackoverflow.com/questions/36620656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What you are hinting at in your comment to Marc Cabos' answer is [Threading](https://docs.python.org/3/library/threading.html) There are several ways Python can use the functionality of other files. If the content of `test.py` can be encapsulated in a function or class, then you can `import` the relevant parts into yo...
Yes you can use Python to control another program using stdin/stdout, but when using another process output often there is a problem of buffering, in other words the other process doesn't really output anything until it's done. There are even cases in which the output is buffered or not depending on if the program is ...
13,238,357
I face a problem when using Scrapy + Mongodb with Tor. I get the following error when I try to have a mongodb pipeline in Scrapy. ``` 2012-11-05 13:41:14-0500 [scrapy] DEBUG: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware |S-chain|-<>-127.0.0...
2012/11/05
[ "https://Stackoverflow.com/questions/13238357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/139909/" ]
``` pymongo.errors.AutoReconnect: could not connect to localhost:27017: [Errno 111] Connection refused ``` It seems you cannot connect to the localhost on port 27017. Is this the correct port and correct host? Make sure about that, also make sure mongodb server is running on the background otherwise you will never co...
It might be that it's trying to redirect your MongoDB connection (localhost:27017) to TOR. If you want to exclude localhost connections from proxychains, you can add the following line to your */etc/proxychains.conf*: ``` localnet 127.0.0.1 000 255.255.255.255 ```
13,238,357
I face a problem when using Scrapy + Mongodb with Tor. I get the following error when I try to have a mongodb pipeline in Scrapy. ``` 2012-11-05 13:41:14-0500 [scrapy] DEBUG: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware |S-chain|-<>-127.0.0...
2012/11/05
[ "https://Stackoverflow.com/questions/13238357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/139909/" ]
``` pymongo.errors.AutoReconnect: could not connect to localhost:27017: [Errno 111] Connection refused ``` It seems you cannot connect to the localhost on port 27017. Is this the correct port and correct host? Make sure about that, also make sure mongodb server is running on the background otherwise you will never co...
Open mongo connection before setting the socks proxy
13,238,357
I face a problem when using Scrapy + Mongodb with Tor. I get the following error when I try to have a mongodb pipeline in Scrapy. ``` 2012-11-05 13:41:14-0500 [scrapy] DEBUG: Enabled spider middlewares: HttpErrorMiddleware, OffsiteMiddleware, RefererMiddleware, UrlLengthMiddleware, DepthMiddleware |S-chain|-<>-127.0.0...
2012/11/05
[ "https://Stackoverflow.com/questions/13238357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/139909/" ]
It might be that it's trying to redirect your MongoDB connection (localhost:27017) to TOR. If you want to exclude localhost connections from proxychains, you can add the following line to your */etc/proxychains.conf*: ``` localnet 127.0.0.1 000 255.255.255.255 ```
Open mongo connection before setting the socks proxy
48,734,784
so im working on this code for school and i dont know much about python. Can someone tell me why my loop keeps outputting invalid score when the input is part of the valid scores. So if i enter 1, it will say invalid score but it should be valid because i set the variable valid\_scores= [0,1,2,3,4,5,6,7,8,9,10]. This c...
2018/02/11
[ "https://Stackoverflow.com/questions/48734784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9346720/" ]
The error means that the 3rd line is not well-formed: you need a (*blank space*) between `android:id` value and `android:title` key. This is the correct XML: ``` <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/Profile" android:title=...
Go to code in the toolbar and click on reformat code.
19,855,110
I am learning how to use Selenium in `python` and I try to modify a `css` style on <http://www.google.com>. For example, the `<span class="gbts"> ....</span>` on that page. I would like to modify the `gbts` class. ``` browser.execute_script("q = document.getElementById('gbts');" + "q.style.border = '1px solid red';"...
2013/11/08
[ "https://Stackoverflow.com/questions/19855110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1073181/" ]
You are asking how to get an element by it's CSS class using JavaScript. Nothing to do with Selenium *really*. Regardless, you have a few options. You can first grab the element using Selenium (so here, yes, Selenium is relevant): ``` element = driver.find_element_by_class_name("gbts") ``` With a reference to this ...
Another pure JavaScript option which you may find gives you more flexibility is to use `document.querySelector()`. Not only will it automatically select the first item from the results set for you, but additionally say you have multiple elements with that class name, but you know that there is only one element with th...