abspath returns different results when py_compile input path is different in Python?

2018-02-12 Thread lampahome
I want to know abspath of python script followed by steps below. 1. *built it to byte code by py_compile.* 2. *execute it to check abspath.* But I got *2 results* when I execute it.I found the *results based on the path of script* followed by py_compile. Here is my script test.py : import

Re: abspath returns different results when py_compile input path is different in Python?

2018-02-12 Thread lampahome
so py_compile.compile() doesn't normalize the filename, but it will pass the input filename to co_filename? 2018-02-12 19:27 GMT+08:00 eryk sun : > On Mon, Feb 12, 2018 at 9:40 AM, lampahome wrote: > > I want to know abspath of python script followed by steps below. > > &g

matplotlib.plot.show always blocks the execution of python script

2018-11-01 Thread lampahome
I want to plot a graph and *still run following code without closing the graph automatically like Matlab does*. I try plt.show(block=False) , it failed and appear in a small moment then close itself. I also try plt.draw() or interactive mode , it failed, too. plt.draw() will block until I close i

Does this behavior have a better design pattern?

2018-11-07 Thread lampahome
I have two categories A,B, and A has 2 items A1,A2 B have 2 items B1, B2. I have two class A and B, and A will handle A1,A2, B handle B1,B2. I want to parse one of A1,A2,B1,B2 to script and generate the corresponding class(object). Ex: Both in class A and B, all have func1(), func2(). What I tho

Re: Does this behavior have a better design pattern?

2018-11-07 Thread lampahome
> > > The rest is just cruft ;) > > > > *Is there better design pattern for me?* > > If A does B to C, is that a crime? > No > Your problem description suffers from overgeneralisation. > > Generally speaking you get better solutions when you ask yourself > "How can I solve this problem effici

how can I solve this problem simply and clearly

2018-11-08 Thread lampahome
I have two categories A,B, and A has 2 items A1,A2, and B have 2 items B1, B2. I have two class A and B, and A will handle A1,A2, B handle B1,B2. I want to parse one of A1,A2,B1,B2 to script and generate the corresponding class(object). Ex: Both in class A and B, all have func1(), func2(). What

Better way to recontruct a continuous and repeated array with low time complexity?

2018-12-20 Thread lampahome
I write program to do experiment about time series(weekly) with machine learning. I record changes of everyday of each ID and Count. I read the csv as dataset like below: ID, Count 1,30 // First Day 2,33 3,45 4,11 5,66 7,88 1,32 // 2nd Day 2,35 3,55 4,21 5,36 7,48 I have two array X, y. I want to

FDs will be closed after exception automatically in python2.7?

2019-06-10 Thread lampahome
as title, I confused will fd will be close after exception automatically? Like: try: fd=open("file","w+") fd.get() //any useless function of fd except Exception: print 'hi' -- https://mail.python.org/mailman/listinfo/python-list

How to use regex to search string between {}?

2019-08-23 Thread lampahome
I want to parse a path string with multiple files and try to figure out a one-line way. If I have path: /home/admin/hello/yo/{h1,h2,h3,h4} What I thought is use regex.search, but the pattern always failed. I use below: import re path = /home/admin/hello/yo/{h1,h2,h3,h4} r = re.search('{.}', path

python3 subprocess run sudo cmd in remote failed

2019-09-16 Thread lampahome
Hello, I use python3.5 and found no way to solve this problem >from subprocess import Popen, PIPE >ps = Popen('ssh -o \'StrictHostKeyChecking no\' hello@192.168.80.11 \'sudo sysctl -w vm.drop_caches=3\', stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=0, shell=True) > hello@192.168.80.11's password

Re: python3 subprocess run sudo cmd in remote failed

2019-09-16 Thread lampahome
> > Well, there's a Python library called "paramiko" which implements ssh. > That might help. > > Later I will try lol. > Note also that since stdin and stdout are pipes and not the terminal > then ssh will not be interactive, and will not allocate a tty at the far > end either. You can get ssh t

Any socket library to communicate with kernel via netlink?

2019-11-18 Thread lampahome
As title, I tried to communicate with kernel via netlink. But I failed when I receive msg from kernel. The weird point is sending successfully from user to kernel, failed when receiving from kernel. So I want to check code in 3rd library and dig in, but always found library called netlinkg but it

Pickle failed __getstate__ on my customized class inherited dict

2019-11-19 Thread lampahome
I make a class Wrapper inherited from dict and met problem when I want to pickle it. Is there anyway to make __getstate__ of Wrapper to output a normal dict?(Output a dict will help pickleing easily) === code === import pickle class Wrapper(dict): def __getattr__(self, attr): return

Use epoll but still lose packet

2019-11-20 Thread lampahome
I use epoll to listen events to receive packet from remote client via tcp socket And I found it still lose packet from remote client when client sends 128 messages to me. Is there any tips to avoid this? thx I only use a while loop to catch events like below: import select, socket sock = socket.

Re: Use epoll but still lose packet

2019-11-20 Thread lampahome
Dennis Lee Bieber 於 2019年11月21日 週四 上午2:17寫道: > On Wed, 20 Nov 2019 18:51:31 +0800, lampahome > declaimed the following: > > > > >I only use a while loop to catch events like below: > >import select, socket > >sock = socket.socket(socket.AF_INET,

Does module socketserver using epoll in python3?

2019-11-28 Thread lampahome
As title, I want to use socketserver to replace my own server code to maintain ealsier. But I don't found any info about tech. detail of socketserver, epoll is important. Can anyone tell me? -- https://mail.python.org/mailman/listinfo/python-list

Re: Does module socketserver using epoll in python3?

2019-11-28 Thread lampahome
> > The source code is here: > https://github.com/python/cpython/blob/master/Lib/socketserver.py . You > should find all the technical details you are looking for in it. > > # poll/select have the advantage of not requiring any extra file > descriptor,# contrarily to epoll/kqueue (also, they requi

What does the blue color section in background mean?

2019-12-04 Thread lampahome
I tried to plot graph about a time-series with library statsmodel. I decide to plot autocorrelation function, but I don't know the blue section in the example graph mean... Can anyone tell me? The plot_acf example link: https://www.statsmodels.org/dev/generated/statsmodels.graphics.tsaplots.plot

How to specific multiple dtypes in numpy.ndarray?

2019-12-19 Thread lampahome
I meet performance is low when I use struct.unpack to unpack binary data. So I tried to use numpy.ndarray But meet error when I want to unpack multiple dtypes Can anyone teach me~ Code like below: # python3 import struct import numpy as np s1 = struct.Struct("@QIQ") ss1 = s1.pack(1,11,111) np.nd

How to improve epoll speed when recv from kernel via netlink?

2019-12-19 Thread lampahome
I tried to receive msg from kernel via netlink of socket. And I use epoll to receive netlink events whenever it comes from kernel to user space. But I found the performance is poor e.g. epoll costs 90% time of execution time after I profile it by cProfile module. Are there any tips to improve th

Can anyone share experience about python backend developer?

2020-02-17 Thread lampahome
I have 3+years developer experience in python, but I always develop about peer-to-peer service. Have no backend experience in python. But now I want to change to backend engineer, somebody shares their job is to do like 1. Develop customize API to receive data from global 2. Develop tools with k8s