You can freely leave Pycharm out of equation.
In that case, there is a question how to force subclass to implement setter
method?
--
https://mail.python.org/mailman/listinfo/python-list
This also works with no errors:
from abc import ABC, abstractmethod
class C(ABC):
@property
@abstractmethod
def my_abstract_property(self):
pass
@my_abstract_property.setter
@abstractmethod
def my_abstract_property(self, val):
pass
class D(C):
my
If my subclass is as this:
from subclassing.abstract.BaseSomeAbstract import BaseSomeAbstract
class ChildSomeAbstract(BaseSomeAbstract):
@property
def abs_prop(self):
return self._abs_prop
I can create an instance of it with no errors. So
x = ChildSomeAbstract()
works with no p
I would like to have an abstract class in which I will have an abstract
property. So I used Pycharm in order to create an abstract (base) class:
import abc
class BaseSomeAbstract(abc.ABC):
_abs_prop = None
@property
@abc.abstractmethod
def abs_prop(self):
return self._a
Thanks for the video. Now it is clear to me what has happened and why copy
solves the problem.
--
https://mail.python.org/mailman/listinfo/python-list
params = {} if params is None else params.copy()
has solved the problem.
I have provided just a toy example here. Execute method actually takes
dict[str, List]. List contains objects. Each object has two properties, so I
have a logic that analyzes these properties and returns None or List as a
Hi,
consider this example:
from typing import Dict, List
class chk_params:
def execute(self, params: Dict[str, List] = None):
if params is None:
params = {}
for k, v in params.items():
params[k] = [val + 10 for val in v]
return params.values
OK, as I can see nothing is enforced but I can use mypy and tests for the
purpose.
As I am using pycharm, looks like I need a plugin for mypy.
There are two of them out there:
non official: https://plugins.jetbrains.com/plugin/11086-mypy
and official: https://plugins.jetbrains.com/plugin/13348-my
Hi,
If I run this code:
class Property:
def __init__(self, var: int):
self.a: int = var
@property
def a(self):
return self.__a
@a.setter
def a(self, var: int):
if var > 0 and var % 2 == 0:
self.__a = var
else:
self.__a
Consider this code:
class SetGet:
_x = 1
@property
def x(self):
return self._x
@x.setter
def x(self, value):
self._x = value
class Dynamic:
x = 1
if __name__ == '__main__':
a = SetGet()
print(f'x = {a.x}')
a.x = 2
print(f'x = {a.x}'
Well the problem that I am facing with is, that I have to establish interface
between python and outer system.
Original question was about creation of input object (data that I have received
from outer system). If I accept recommendation to use "from_" instead of
"from", it could work, for proc
Hi,
if I define class like this one:
class abc:
def __init__(self):
self._from = None
@property
def from(self):
return self._from
@from.setter
def from(self, value):
self._from = value
I get the error SyntaxError: invalid syntax because of the prop
Hi Peter.
Finally I got it. :)
That's it. It works. Thanks.
So, in each class, I will in init method execute:
self.logger = logging.getLogger()
and than everywhere use self.logger.debug('...') in order to produce the
message.
Best regards.
--
https://mail.python.org/mailman/listinfo/python-li
> You create two stream handlers that both log to stderr -- one with
> basicConfig() and one explicitly in your code. That's probably not what you
> want.
How can I just add terminator = '\r\n' to the code bellow?
Where should I put it?
import logging
LOG_LEVEL = logging.getLevelName('DEBUG')
Furthermore, I must disable logging to stdout.
--
https://mail.python.org/mailman/listinfo/python-list
Is this OK?
import logging
LOG_LEVEL = logging.getLevelName('DEBUG')
logging.basicConfig(level=LOG_LEVEL,
format='%(asctime)s %(levelname)s %(name)s %(funcName)-20s
%(message)s',
datefmt='%d.%m.%Y %H:%M:%S')
stderr = logging.StreamHandler()
stderr.termin
Hi,
I have a case in which I have to use custom function for logging.
For example, all messages should go to stderr and end with '\r\n'.
Can I somehow use standard python logging module but send all message to stderr
with '\r\n' line endings?
Regards
--
https://mail.python.org/mailman/listinfo
Hi,
I have to talk to outer system by stdin/stdout.
Each line that comes to stdin should be processed and its result returned back
to stdout. Logging should go to stderr.
How to design a class that will listed to stdin and call required methods in
order to process the data?
Regards
--
https:/
You are probably right.
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
I should provide python code for (Spring) microservice patform.
In microservice paradigm, each microservice should do a simple task, so python
code beneath it should be very small.
As a PyCharm (community) user, I don't know how to set up such development
environment.
Each microservice co
Yes it is. Thanks.
> A slightly better solution would be:
>
> cnv_sel = re.sub(r":(\w+)", r"${\1}", sel)
--
https://mail.python.org/mailman/listinfo/python-list
I have to execute the same sql in two different programs.
Each of them marks parameters differently.
Anyway, I have found the solution.
cnv_sel = re.sub(r"(:(.+?)\b)", r"${\2}", sel)
Reagards.
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
if I have a string:
sql = """
where 1 = 1
and field = :value
and field2 in (:list)
"""
I would like to replace every word that starts with ":" in the following way:
1. replace ":" with "${"
2. at the end of the word add "}"
An example should look like this:
where 1 = 1
and field = ${valu
Thanks. As I can see python 3.7 is the best option.
Thank you very very muchs for the code as well.
Best regards.
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
I am looking for a way to save ini file with application section/option
combination. Something like the following:
[Default]
ROOT_DIR= /home/...
RUN = True
COUNTER = 5
LAST_VALUE = 5.6
TEST_FILES_LIST=['a.txt', 'b.txt', 'c.txt']
TEST_FILES_DICT={'CASE1' : ['a.txt', 'b.txt'], 'CASE2': ['c.
Hi Matt,
> (Including python-list again, for lack of a reason not to. This
> conversation is still relevant and appropriate for the general Python
> mailing list -- I just meant that the pydata list likely has many more
> Pandas users/experts, so you're more likely to get a better answer,
> faster
On Monday, 14 May 2018 13:05:24 UTC+2, zlju...@gmail.com wrote:
> Hi,
>
> I have dataframe with CRM_assetID column as category dtype:
>
> df.info()
>
>
> RangeIndex: 1435952 entries, 0 to 1435951
> Data columns (total 75 columns):
> startTime1435952 non-null object
Hi,
I have dataframe with CRM_assetID column as category dtype:
df.info()
RangeIndex: 1435952 entries, 0 to 1435951
Data columns (total 75 columns):
startTime1435952 non-null object
CRM_assetID 1435952 non-null category
searching a dataframe
Thomas, thank you very very much, this was exactly what I needed.
Thanks again and best regards.
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
I have pandas DataFrame with several columns. I have to pass all columns as
separate parameter to a function.
Something like this if I have 4 columns.
f, p = stats.f_oneway(df_piv.iloc[:, 0], df_piv.iloc[:, 1], df_piv.iloc[:, 2],
df_piv.iloc[:, 3])
As number of columns varies, how to do
Hi,
I have a script that should accept sql query as a parameter and change it in a
way. For now I have a file in which I have put sql query and than python script
opens it and do everything else.
Is it possible to run python script that will open editor and let me paste sql
query in the editor
Thanks guys.
--
https://mail.python.org/mailman/listinfo/python-list
Is it possible to create hard links on windows with ntfs?
On linux I can use os.link, but how about windows?
Regards.
--
https://mail.python.org/mailman/listinfo/python-list
On Wednesday, 18 April 2018 19:34:37 UTC+2, MRAB wrote:
> > Hi,
> >
> > I have a sql query in which all variables declared as :variable should be
> > changed to ${variable}.
> >
> > for example this sql:
> >
> > select *
> > from table
> > where ":x" = "1" and :y=2
> > and field in (:string)
Hi,
I have a sql query in which all variables declared as :variable should be
changed to ${variable}.
for example this sql:
select *
from table
where ":x" = "1" and :y=2
and field in (:string)
and time between :from and :to
should be translated to:
select *
from table
where "${x}"
On Wednesday, 11 April 2018 21:19:44 UTC+2, José María Mateos wrote:
> On Wed, Apr 11, 2018, at 14:48, zlj...com wrote:
> > I have a dataframe:
> > [...]
>
> This seems to work:
>
> df1 = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan],
> 'B'
I have a dataframe:
import pandas as pd
import numpy as np
df = pd.DataFrame( { 'A' : ['a', 'b', '', None, np.nan],
'B' : [None, np.nan, 'a', 'b', '']})
A B
0 a None
1 b NaN
2 a
3 None b
4 NaN
I would like to create column C in
Processing is I/O and CPU bound. :(
--
https://mail.python.org/mailman/listinfo/python-list
That's right. Update task has precedence.
Looks like it is not an easy task.
Regards.
--
https://mail.python.org/mailman/listinfo/python-list
I would like to have a script that collects data every minute and at the same
time serve newly collected data as web pages.
Timely collecting data is more important than serving web pages, so collecting
data should have priority and should never be interrupted by serving web pages.
My first ide
> This is not an in-place operation: it returns a style which you can then
> render.
>
> style = df.style.apply(function2, axis=1)
> html = style.render()
>
> appears to work.
After your suggestion, rows are properly colored, but now I have lost all table
lines, font is smaller...
Is there an o
> This is not an in-place operation: it returns a style which you can then
> render.
>
> style = df.style.apply(function2, axis=1)
> html = style.render()
>
> appears to work.
This was a missing link.
Thank you very very much Thomas.
Regards and best wishes.
--
https://mail.python.org/mailm
Hi,
I have to compare two pandas dataframes and find difference between each row.
For example, in the code bellow, rows with index 0 and 3 are intentionally
different.
Row 0 is different in field A, and row 3 is different in field 3.
After merging dataframes, I can concentrate to the dfm with d
Hi,
the following code never applies style and I cannot figure out why.
Can someone please help?
import pandas as pd
def function2(row):
if row.A == True:
color = '#FF'
else:
color = '#00FF00'
background_color = 'background-color: {}'.format(color)
return [b
I have sliced the pandas dataframe
end_date = df[-1:]['end']
type(end_date)
Out[4]: pandas.core.series.Series
end_date
Out[3]:
48173 2017-09-20 04:47:59
Name: end, dtype: datetime64[ns]
1. How to get rid of index value 48173 and get only "2017-09-20 04:47:59"
string? I have to call RE
I have a dataframe with epoh dates, something like this:
df = pd.DataFrame( { 'epoch' : [1493928008, 1493928067, 1493928127, 1493928310,
1493928428, 1493928547]})
I want to create a new column with epoch converted to -mm-dd as string.
Actually, I have a epoch column, and I would like to us
On Tuesday, 30 May 2017 22:33:50 UTC+2, Peter Otten wrote:
> z...@gmail.com wrote:
>
> > I have a dataframe:
> >
> >
> > df = pd.DataFrame({
> >'x': [3,4,5,8,10,11,12,13,15,16,18,21,24,25],
> >'a': [10,9,16,4,21,5,3,17,11,5,21,19,3,9]
> > })
> >
> > df
> > Out[30]:
> > a x
> > 0
I have a dataframe:
df = pd.DataFrame({
'x': [3,4,5,8,10,11,12,13,15,16,18,21,24,25],
'a': [10,9,16,4,21,5,3,17,11,5,21,19,3,9]
})
df
Out[30]:
a x
0 10 3
19 4
2 16 5
34 8
4 21 10
55 11
63 12
7 17 13
8 11 15
95 16
10 21 18
11 19 21
12
In dataframe
import pandas as pd
data = {'model': ['first', 'first', 'second', 'second', 'second', 'third',
'third'],
'dtime': ['2017-01-01_112233', '2017-01-01_112234',
'2017-01-01_112234', '2017-01-01_112234', '2017-01-01_112234',
'2017-01-01_112235', '2017-01-01_112235'],
}
It works. Thank you very much. :)
--
https://mail.python.org/mailman/listinfo/python-list
This doesn't work:
import pandas as pd
def myfunc():
return 'Start_{}_{}_{}_{}_End'.format(df['coverage'], df['name'],
df['reports'], df['year'])
data = {'name': ['Jason', 'Molly', 'Tina', 'Jake', 'Amy'],
'year': [2012, 2012, 2013, 2014, 2014],
'reports': [4, 24, 31, 2, 3],
I have done that. The best article I have found is:
https://getpocket.com/a/read/1651596570
So far I have tried exifread, exiftool, mediainfo, but looks like I will have
to combine several tools in order to get the information that I need.
Major problem is with the model. Looks like every manufac
On Tuesday, 14 March 2017 19:54:18 UTC+1, MRAB wrote:
> It might be worth trying "ImageMagick".
ImageMagick is only for pictures. :(
Do you have a suggestion for videos?
--
https://mail.python.org/mailman/listinfo/python-list
I am looking for the way to extract two simple information from pictures/videos
that I have recorded with different devices that I own: model (of the device
that has recorded) and recordings (local) creation time.
So far, I tried different approaches.
I tried to use pymediainfo (https://pypi.p
I am looking for the way to extract two simple information from pictures/videos
that I have recorded with different devices that I own: model (of the device
that has recorded) and recordings (local) creation time.
So far, I tried different approaches.
I tried to use pymediainfo (https://pypi.p
That was it.
Thanks guys for your help.
Best regards.
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
in python3 my variable looks like this:
a = b'{"uuid":"5730e8666ffa02.34177329","error":""}'
str(a) = 'b\'{"uuid":"5730e8666ffa02.34177329","error":""}\''
If I execute the following command I get the error:
>>> json.loads(str(a))
Traceback (most recent call last):
File "C:\Program Files (
> There's probably some Angular JS code involved with this. Look at the
> source (not the page source, the source code in the developer's
> tools).
Is it possible to get that code using python?
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
on page:
https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film
there is a picture and in the middle of the picture there is a text "Prijavite
se za gledanje!"
If I open the page in firefox and then use menu Tools > Web developer > Page
sour
> Why? As important as it is to show code, you need to show what actually
> happens and what error message is produced.
If you run the code you will see that html that I got doesn't have link to the
flash video. I should somehow do something (press play video button maybe) in
order to get html
I tried to use the following code:
from bs4 import BeautifulSoup
from selenium import webdriver
PHANTOMJS_PATH =
'C:\\Users\\Zoran\\Downloads\\Obrisi\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe'
url =
'https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dok
Hi,
can you please recommend to me a python3 library that I can use for scrapping
JS that works on windows as well as linux?
Regards.
--
https://mail.python.org/mailman/listinfo/python-list
On Friday, 29 April 2016 22:40:10 UTC+2, Chris Angelico wrote:
> Since you're asking on this list, I'll assume you're using Beautiful
> Soup and/or youtube-dl. You'll need to go into more detail about what
> you're trying to do, and where the Python problem is.
>
> ChrisA
The situation is very s
Hi,
I am looking for a way to download a flash video from the page:
https://hrti.hrt.hr/#/video/show/2203605/trebizat-prica-o-jednoj-vodi-i-jednom-narodu-dokumentarni-film
The html code bellow the page is fairly simple, but I can't figure out how to
get the file.
In case somebody have an idea
> If what you really need is a voting application, you can look at
> https://github.com/mdipierro/evote which the PSF uses for its elections.
It is not a voting application (I will have more than yes/no answers).
I just want to keep an example simple.
Anyway, I will look into voting application
> You have a couple options that occur to me:
>
> 1) set up an SMTP server somewhere (or use the existing one you're
> receiving this email at in the event you're getting it as mail
> rather than reading it via NNTP or a web interface) to receive the
> mail, then create a Python script to poll tha
> I'm assuming this is a website. If so, why not use a form with a checkbox?
One of ideas is to put two url's in the email, one for yes and the other one
for no.
I am also thinking about reading/parsing the reply mail.
Regards.
--
https://mail.python.org/mailman/listinfo/python-list
Hi,
> def get_html(...):
> try:
> ... actually go get the info
> return info
> except (ConnectionError, OSError, SocketError) as e:
> raise ContentNotFoundError from e
Personally, I never liked "early returns". I would rather used a variable and
the last line in t
Hi,
You are right. I am trying to address a few questions at the same time.
As English is not my first language, I can only say that you have addressed
them very well. Thanks.
1. Where to put the try/except block, inside or outside the function
2. How to deal with un-anticipated exceptions
3.
Hi,
I know how to send an email, but I would like to be able to receive a reply and
act accordingly.
Mail reply should contain yes/no answer.
I don't know whether email is appropriate for such function.
Maybe better idea would be to have links in email body, one for yes, another
for no that wil
> Which would you prefer?
So if I am just checking for the ConnectionError in get_html and a new
exception arises, I will have traceback to the get_html function showing that
unhandled exception has happened.
Now I have to put additional exception block for managing the new exception in
the get
On Monday, 2 November 2015 21:59:45 UTC+1, Ian wrote:
> I'm having a hard time understanding what question you're asking.
:)
I am really having a hard time to explain the problem as English is not my
first language.
> You
> have a lot of discussion about where to handle exceptions,
That's
> The best way is probably to do nothing at all, and let the caller handle
> any exceptions.
In that case every call of the get_html function has to be in the try/except
block with many exceptions.
Sometimes, it is enough just to know whether I managed to get the html or not.
In that case, I coul
Let's say that I have the following simple function:
def get_html(url):
wpage = requests.get(url)
return wpage.text
How to handle exceptions properly that can arise during execution of the
requests.get(url)?
If I call this function with
try:
html = get_html('www.abc.com/index
> Ah - looking at the response headers, they include "Transfer-Encoding
> chunked" - I don't think urlopen handles chunked responses by default,
> though I could be wrong, I don't have time to check the docs right now.
>
> The requests library (https://pypi.python.org/pypi/requests) seems to han
> Hello,
>
> urlopen returns an HttpResponse
> object(https://docs.python.org/3/library/http.client.html#httpresponse-objects).
> You need to call read() on the return value to get the page
> content, or you could consider the getheader method to check for a Content-
> Length header.
>
> Hop
Hi,
if I put the link in the browser, I will be offered to save the file to the
local disk.
If I execute these few lines of code, I will get None:
import urllib.request
url = 'http://radio.hrt.hr/prvi-program/aod/download/118467/'
site = urllib.request.urlopen(url)
print('File size:', site.len
I have a working solution. :)
The function below will download a file securely.
Thank anyone who helped. I wouldn't be able to write this function without your
help.
I hope, someone else will benefit from our united work.
Best regards.
import os
import urllib.request
def Download(rfile, lfile):
This is my final version which doesn't work. :(
Actually, it works with another file on another server, but doesn't work with
mp4 files on this particular server.
I really don't know what to do?
Regards.
import os
import urllib.request
def Download(rfile, lfile):
retval = False
if os
New version with chunks:
import os
import urllib.request
def Download(rfile, lfile):
retval = False
if os.path.isfile(lfile):
lsize = os.stat(lfile).st_size
else:
lsize = 0
req = urllib.request.Request(rfile)
req.add_header('Range', "bytes={}-".format(lsize)
But how to read chunks?
--
https://mail.python.org/mailman/listinfo/python-list
Currently I am executing the following code:
import os
import urllib.request
def Download(rfile, lfile):
retval = False
if os.path.isfile(lfile):
lsize = os.stat(lfile).st_size
else:
lsize = 0
req = urllib.request.Request(rfile)
req.add_header('Range', "byte
On Wednesday, 1 July 2015 01:43:19 UTC+2, Cameron Simpson wrote:
> On 30Jun2015 08:34, zljubi...@gmail.com wrote:
> >I would like to download a file (http://video.hrt.hr/2906/otv296.mp4)
> >If the connection is OK, I can download the file with:
> >
> >import urllib.request
> >urllib.request.urlre
Hi,
I would like to download a file (http://video.hrt.hr/2906/otv296.mp4)
If the connection is OK, I can download the file with:
import urllib.request
urllib.request.urlretrieve(remote_file, local_file)
Sometimes when I am connected on week wireless (not mine) network I get
WinError 10054 exce
84 matches
Mail list logo