Duplicate Output
Hi
Debian stretch OS
KDE Desktop
Code written with Kate
Run in command line with $python getFileNames.py
Code:
from os import walk
import subprocess
f = []
x = ""
for (dirpath, dirnames, filenames) in walk('.'):
print(filenames)
This prints [][]
What am I doing wrong or how do I remove the duplicate list.
Gary R.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Duplicate Output
Gary Roach wrote:
> Hi
>
> Debian stretch OS
> KDE Desktop
> Code written with Kate
> Run in command line with $python getFileNames.py
>
> Code:
>
> from os import walk
> import subprocess
>
> f = []
> x = ""
> for (dirpath, dirnames, filenames) in walk('.'):
> print(filenames)
>
> This prints [][]
>
> What am I doing wrong or how do I remove the duplicate list.
If there is a second list that list is for a subdirectory of ".". To see
that add
> for (dirpath, dirnames, filenames) in walk('.'):
print(dirpath)
> print(filenames)
to your code. If you only want the names of files in the current directory
you can break out of the loop after the first iteration
> for (dirpath, dirnames, filenames) in walk('.'):
> print(filenames)
break
or use next():
filenames = next(walk("."))[2]
print(filenames)
--
https://mail.python.org/mailman/listinfo/python-list
Re: Duplicate Output
Peter Otten wrote:
> or use next():
>
> filenames = next(walk("."))[2]
> print(filenames)
Be warned though that if you try this with a non-existent or otherwise
inaccessible directory you will get an exception:
$ sudo mkdir forbidden
$ sudo chmod a-r forbidden
$ python3 -c 'import os; next(os.walk("forbidden"))'
Traceback (most recent call last):
File "", line 1, in
StopIteration
--
https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
2016-01-26 18:26 GMT+01:00 mustang :
>
>> open("myData.dat", "w").close()
>>
>> while True:
>> temp = sensor.readTempC()
>> riga = "%f\n" % temp
>> with open("myData.dat", "a") as f:
>> f.write(riga)
>> time.sleep(1)
>
> yes great it works!thanks a lot!
> Anyway to refresh temperature I've to recall anytime the php page.
> My idea is to read for example the first line every x seconds...it should
> work.
> Is it possible to use python and not php to plot data?
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
I'm not sure to understand how you are using php, but indeed you can
use python to plot data (have a look at matplotlib, for instance) and
also to make dynamic web pages (Flask, django).
Best.
--
https://mail.python.org/mailman/listinfo/python-list
Windows - Embedded Python in C++: ImportError: DLL load failed. Python expert advice needed.
I've been busy porting a Linux code to Windows, and originally decided to go
for the mingw-w64 toolchain set, with gcc-4.8 and win32 threading model.
I'm embedding Python in C++ code, and I need to be able to import specific
modules, like PySide, to eventually embed an IPython qtconsole in a C++ Qt
window. This all works under Linux, so the approach is sound. And everything
compiled properly under Windows too. PySide was installed via pip.
Now, from a normal Python/IPython console on the Windows system, I can import
what I want:
import PySide.QtCore
No problem here, as expected. But when on the embed side I do:
PyRun_SimpleString("import PySide.QtCore");
I get the following error:
Traceback (most recent call last):
File "", line 2, in
ImportError: DLL load failed: The specified procedure could not be found.
When I import:
PyRun_SimpleString("import PySide");
It works, but I get an empty PySide object. If I import "sys", "os", or
"math", all the modules work as expected though, which is probably due to the
fact that they are compiled in python27.dll.
So I'm a bit puzzled as to what is happening. Why can I start a Python embedded
interpreter, load the builtin modules but not external modules? (I tried other
modules like matplotlib / numpy, which didn't work either).
I very strongly suspect the problem to be a linking error, as python27.dll is
linked to msvcr90.dll, and mingw-w64 links to msvcrt.dll, meaning my library
will be linked to the wrong dll. But in that case, why am I able to load and
run Python nonetheless?
Thanks for the help!
--
https://mail.python.org/mailman/listinfo/python-list
not run in my laptop
How I Install python for 64 bit -- https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
mustang wrote:
>> open("myData.dat", "w").close()
>>
>> while True:
>> temp = sensor.readTempC()
>> riga = "%f\n" % temp
>> with open("myData.dat", "a") as f:
>> f.write(riga)
>> time.sleep(1)
>yes great it works!thanks a lot!
>Anyway to refresh temperature I've to recall anytime the php page.
>My idea is to read for example the first line every x seconds...it
>should work.
>Is it possible to use python and not php to plot data?
You even could use python for the webserver. Read the docs for the module
"SimpleHTTPServer".
--
https://mail.python.org/mailman/listinfo/python-list
PyVmMonitor 1.0.1 released
PyVmMonitor 1.0.1 is now available for download *Release Highlights:* - Pstats files may be passed in the command line to be opened in pyvmmonitor-ui. - Fixed issue opening PyVmMonitor in Mac OS (El Capitan). - Opening PStats file may fail because it's linked to a Python version, so, in such a situation, PyVmMonitor allows opening it using a different interpreter. - Command line examples are properly wrapped with quotes on Windows. See: http://www.pyvmmonitor.com for more information. *What is PyVmMonitor?* PyVmMonitor is a profiler with a simple goal: being the best way to profile a Python program. *Features* - Attach profiler to a running (CPython) program - Deterministic profiling through cProfile/profile integration - On demand profiling with Yappi integration - Analyze existing PStats results - Open DOT files - Programatic API access - Profile on a different machine - Multiple processes support (multiprocessing, django...) - Live sampling/CPU view - Select time range - Group samples by method or line - PyDev integration - PyCharm integration Enjoy! Fabio Zadrozny Software Developer LiClipse http://www.liclipse.com PyDev - Python Development Environment for Eclipse http://pydev.org http://pydev.blogspot.com PyVmMonitor - Python Profiler http://www.pyvmmonitor.com/ -- https://mail.python.org/mailman/listinfo/python-list
Re: not run in my laptop
On 2016-01-27, anubha agrawal wrote: > How I Install python for 64 bit $ sudo emerge python -- Grant Edwards grant.b.edwardsYow! I wonder if I could at ever get started in the gmail.comcredit world? -- https://mail.python.org/mailman/listinfo/python-list
Re: not run in my laptop
On Wed, Jan 27, 2016 at 9:35 AM, Grant Edwards wrote: > On 2016-01-27, anubha agrawal wrote: > > > How I Install python for 64 bit > > Standard info required: OS, version, version of python. What have you tried? what went wrong? Be specific. -- Joel Goldstick http://joelgoldstick.com/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about asyncio and blocking operations
"Ian Kelly" wrote in message
news:CALwzidk-RBkB-vi6CgcEeoFHQrsoTFvqX9MqzDD=rny5boc...@mail.gmail.com...
On Tue, Jan 26, 2016 at 7:15 AM, Frank Millman wrote:
>
> If I return the cursor, I can iterate over it, but isn't this a blocking
> operation? As far as I know, the DB adaptor will only actually retrieve
> the
> row when requested.
>
> If I am right, I should call fetchall() while inside get_rows(), and
> return
> all the rows as a list.
>
You probably want an asynchronous iterator here. If the cursor doesn't
provide that, then you can wrap it in one. In fact, this is basically
one of the examples in the PEP:
https://www.python.org/dev/peps/pep-0492/#example-1
Thanks, Ian. I had a look, and it does seem to fit the bill, but I could not
get it to work, and I am running out of time.
Specifically, I tried to get it working with the sqlite3 cursor. I am no
expert, but after some googling I tried this -
import sqlite3
conn = sqlite3.connect('/sqlite_db')
cur = conn.cursor()
async def __aiter__(self):
return self
async def __anext__(self):
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, self.__next__)
import types
cur.__aiter__ = types.MethodType( __aiter__, cur )
cur.__anext__ = types.MethodType( __anext__, cur )
It failed with this exception -
AttributeError: 'sqlite3.Cursor' object has no attribute '__aiter__'
I think this is what happens if a class uses 'slots' to define its
attributes - it will not permit the creation of a new one.
Anyway, moving on, I decided to change tack. Up to now I have been trying to
isolate the function where I actually communicate with the database, and
wrap that in a Future with 'run_in_executor'.
In practice, the vast majority of my interactions with the database consist
of very small CRUD commands, and will have minimal impact on response times
even if they block. So I decided to focus on a couple of functions which are
larger, and try to wrap the entire function in a Future with
'run_in_executor'.
It seems to be working, but it looks a bit odd, so I will show what I am
doing and ask for feedback.
Assume a slow function -
async def slow_function(arg1, arg2):
[do stuff]
It now looks like this -
async def slow_function(arg1, arg2):
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, slow_function_1, arg1, arg2)
def slow_function_1(self, arg1, arg2):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(slow_function_2(arg1, arg2))
async slow_function_2(arg1, arg2):
[do stuff]
Does this look right?
Frank
--
https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
I'm not sure to understand how you are using php, but indeed you can use python to plot data (have a look at matplotlib, for instance) and also to make dynamic web pages (Flask, django). Because I don't know how to do it in python. So I've used php. But I prefer working in python. Best. -- https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
You even could use python for the webserver. Read the docs for the module "SimpleHTTPServer". now I'm using apache. Is it possible to do the same with python+apache or it's better to use SimpleHTTPServer? -- https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
On Wed, Jan 27, 2016 at 10:36 AM, mustang wrote: > > I'm not sure to understand how you are using php, but indeed you can >> use python to plot data (have a look at matplotlib, for instance) and >> also to make dynamic web pages (Flask, django). >> > > Because I don't know how to do it in python. > So I've used php. But I prefer working in python. > Having previously written websites using php, and now a confirmed python developer, you should know this: Php, vbscript, perl, and perhaps other languages allow the interspersal of code and html in the same file. You can't do that with python. So, if you begin to wade into making websites with python you may be a little lost until you grasp the concept of separating code from templates (the html portion) and how you populate your templates with your code values. Django is a popular choice, but some like smaller frameworks like flask, and others. > >> Best. >> >> > -- > https://mail.python.org/mailman/listinfo/python-list > -- Joel Goldstick http://joelgoldstick.com/stats/birthdays -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about asyncio and blocking operations
On Wed, Jan 27, 2016 at 7:40 AM, Frank Millman wrote:
> "Ian Kelly" wrote in message
> news:CALwzidk-RBkB-vi6CgcEeoFHQrsoTFvqX9MqzDD=rny5boc...@mail.gmail.com...
>
>> You probably want an asynchronous iterator here. If the cursor doesn't
>> provide that, then you can wrap it in one. In fact, this is basically
>> one of the examples in the PEP:
>> https://www.python.org/dev/peps/pep-0492/#example-1
>>
>
> Thanks, Ian. I had a look, and it does seem to fit the bill, but I could not
> get it to work, and I am running out of time.
>
> Specifically, I tried to get it working with the sqlite3 cursor. I am no
> expert, but after some googling I tried this -
>
> import sqlite3
> conn = sqlite3.connect('/sqlite_db')
> cur = conn.cursor()
>
> async def __aiter__(self):
>return self
>
> async def __anext__(self):
>loop = asyncio.get_event_loop()
>return await loop.run_in_executor(None, self.__next__)
>
> import types
> cur.__aiter__ = types.MethodType( __aiter__, cur )
> cur.__anext__ = types.MethodType( __anext__, cur )
>
> It failed with this exception -
>
> AttributeError: 'sqlite3.Cursor' object has no attribute '__aiter__'
>
> I think this is what happens if a class uses 'slots' to define its
> attributes - it will not permit the creation of a new one.
This is why I suggested wrapping the cursor instead. Something like this:
class CursorWrapper:
def __init__(self, cursor):
self._cursor = cursor
async def __aiter__(self):
return self
async def __anext__(self):
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, next, self._cursor)
> Anyway, moving on, I decided to change tack. Up to now I have been trying to
> isolate the function where I actually communicate with the database, and
> wrap that in a Future with 'run_in_executor'.
>
> In practice, the vast majority of my interactions with the database consist
> of very small CRUD commands, and will have minimal impact on response times
> even if they block. So I decided to focus on a couple of functions which are
> larger, and try to wrap the entire function in a Future with
> 'run_in_executor'.
>
> It seems to be working, but it looks a bit odd, so I will show what I am
> doing and ask for feedback.
>
> Assume a slow function -
>
> async def slow_function(arg1, arg2):
>[do stuff]
>
> It now looks like this -
>
> async def slow_function(arg1, arg2):
>loop = asyncio.get_event_loop()
>await loop.run_in_executor(None, slow_function_1, arg1, arg2)
>
> def slow_function_1(self, arg1, arg2):
>loop = asyncio.new_event_loop()
>asyncio.set_event_loop(loop)
>loop.run_until_complete(slow_function_2(arg1, arg2))
>
> async slow_function_2(arg1, arg2):
>[do stuff]
>
> Does this look right?
I'm not sure I understand what you're trying to accomplish by running
a second event loop inside the executor thread. It will only be useful
for scheduling asynchronous operations, and if they're asynchronous
then why not schedule them on the original event loop?
--
https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
mustang wrote: >> You even could use python for the webserver. Read the docs for the module >> "SimpleHTTPServer". >now I'm using apache. Is it possible to do the same with python+apache >or it's better to use SimpleHTTPServer? mod_python exists for apache. If your only goal is just a simple website for your temperature sensor you could do it completely with python. If the webserver should serve other pages as well I'd prefer apache with mod_python. -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about asyncio and blocking operations
On Wed, Jan 27, 2016 at 9:15 AM, Ian Kelly wrote: > class CursorWrapper: > > def __init__(self, cursor): > self._cursor = cursor > > async def __aiter__(self): > return self > > async def __anext__(self): > loop = asyncio.get_event_loop() > return await loop.run_in_executor(None, next, self._cursor) Oh, except you'd want to be sure to catch StopIteration and raise AsyncStopIteration in its place. This could also be generalized as an iterator wrapper, similar to the example in the PEP except using run_in_executor to actually avoid blocking. class AsyncIteratorWrapper: def __init__(self, iterable, loop=None, executor=None): self._iterator = iter(iterable) self._loop = loop or asyncio.get_event_loop() self._executor = executor async def __aiter__(self): return self async def __anext__(self): try: return await self._loop.run_in_executor( self._executor, next, self._iterator) except StopIteration: raise StopAsyncIteration Unfortunately this doesn't actually work at present. EventLoop.run_in_executor swallows the StopIteration exception and just returns None, which I assume is a bug. -- https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
Php, vbscript, perl, and perhaps other languages allow the interspersal of code and html in the same file. You can't do that with python. So, if you begin to wade into making websites with python you may be a little lost until you grasp the concept of separating code from templates (the html portion) and how you populate your templates with your code values. Django is a popular choice, but some like smaller frameworks like flask, and others. anyway I'm not interested in building website I've only to plot/show data collecting them from a sensor and plot them in a realtime graph (for example temperature). -- https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
mod_python exists for apache. If your only goal is just a simple website for your temperature sensor you could do it completely with python. If the webserver should serve other pages as well I'd prefer apache with mod_python. my goal is only to collect data and show them or plotting in a graph. So if I can do it only in python better! -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about asyncio and blocking operations
On Wed, Jan 27, 2016 at 10:14 AM, Ian Kelly wrote: > Unfortunately this doesn't actually work at present. > EventLoop.run_in_executor swallows the StopIteration exception and > just returns None, which I assume is a bug. http://bugs.python.org/issue26221 -- https://mail.python.org/mailman/listinfo/python-list
Re: show instant data on webpage
On 2016-01-27, mustang wrote: > >> mod_python exists for apache. If your only goal is just a simple website for >> your temperature sensor you could do it completely with python. If the >> webserver should serve other pages as well I'd prefer apache with mod_python. > > my goal is only to collect data and show them or plotting in a graph. > So if I can do it only in python better! Then I'd use gnuplot or matplotlib. -- Grant Edwards grant.b.edwardsYow! Where does it go when at you flush? gmail.com -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about asyncio and blocking operations
"Ian Kelly" wrote in message news:calwzidn6tvn9w-2qnn2jyvju8nhzn499nptfjn9ohjddceb...@mail.gmail.com... On Wed, Jan 27, 2016 at 7:40 AM, Frank Millman wrote: > > Assume a slow function - > > async def slow_function(arg1, arg2): >[do stuff] > > It now looks like this - > > async def slow_function(arg1, arg2): >loop = asyncio.get_event_loop() >await loop.run_in_executor(None, slow_function_1, arg1, arg2) > > def slow_function_1(self, arg1, arg2): >loop = asyncio.new_event_loop() >asyncio.set_event_loop(loop) >loop.run_until_complete(slow_function_2(arg1, arg2)) > > async slow_function_2(arg1, arg2): >[do stuff] > > Does this look right? I'm not sure I understand what you're trying to accomplish by running a second event loop inside the executor thread. It will only be useful for scheduling asynchronous operations, and if they're asynchronous then why not schedule them on the original event loop? I could be confusing myself here, but this is what I am trying to do. run_in_executor() schedules a blocking function to run in the executor, and returns a Future. If you just invoke it, the blocking function will execute in the background, and the calling function will carry on. If you obtain a reference to the Future, and then 'await' it, the calling function will be suspended until the blocking function is complete. You might do this because you want the calling function to block, but you do not want to block the entire event loop. In the above example, I do not want the calling function to block. However, the blocking function invokes one or more coroutines, so it needs an event loop to operate. Creating a new event loop allows them to run independently. Hope this makes sense. Frank -- https://mail.python.org/mailman/listinfo/python-list
Re: Question about asyncio and blocking operations
"Ian Kelly" wrote in message
news:CALwzidk-RBkB-vi6CgcEeoFHQrsoTFvqX9MqzDD=rny5boc...@mail.gmail.com...
On Tue, Jan 26, 2016 at 7:15 AM, Frank Millman wrote:
>
> If I return the cursor, I can iterate over it, but isn't this a blocking
> operation? As far as I know, the DB adaptor will only actually retrieve
> the
> row when requested.
>
> If I am right, I should call fetchall() while inside get_rows(), and
> return
> all the rows as a list.
>
You probably want an asynchronous iterator here. If the cursor doesn't
provide that, then you can wrap it in one. In fact, this is basically
one of the examples in the PEP:
https://www.python.org/dev/peps/pep-0492/#example-1
Thanks, Ian. I had a look, and it does seem to fit the bill, but I could not
get it to work, and I am running out of time.
Specifically, I tried to get it working with the sqlite3 cursor. I am no
expert, but after some googling I tried this -
import sqlite3
conn = sqlite3.connect('/sqlite_db')
cur = conn.cursor()
async def __aiter__(self):
return self
async def __anext__(self):
loop = asyncio.get_event_loop()
return await loop.run_in_executor(None, self.__next__)
import types
cur.__aiter__ = types.MethodType( __aiter__, cur )
cur.__anext__ = types.MethodType( __anext__, cur )
It failed with this exception -
AttributeError: 'sqlite3.Cursor' object has no attribute '__aiter__'
I think this is what happens if a class uses 'slots' to define its
attributes - it will not permit the creation of a new one.
Anyway, moving on, I decided to change tack. Up to now I have been trying to
isolate the function where I actually communicate with the database, and
wrap that in a Future with 'run_in_executor'.
In practice, the vast majority of my interactions with the database consist
of very small CRUD commands, and will have minimal impact on response times
even if they block. So I decided to focus on a couple of functions which are
larger, and try to wrap the entire function in a Future with
'run_in_executor'.
It seems to be working, but it looks a bit odd, so I will show what I am
doing and ask for feedback.
Assume a slow function -
async def slow_function(arg1, arg2):
[do stuff]
It now looks like this -
async def slow_function(arg1, arg2):
loop = asyncio.get_event_loop()
await loop.run_in_executor(None, slow_function_1, arg1, arg2)
def slow_function_1(self, arg1, arg2):
loop = asyncio.new_event_loop()
asyncio.set_event_loop(loop)
loop.run_until_complete(slow_function_2(arg1, arg2))
async slow_function_2(arg1, arg2):
[do stuff]
Does this look right?
Frank
--
https://mail.python.org/mailman/listinfo/python-list
Re: how to get python version ?
On Thu, Jan 28, 2016 at 4:21 PM, wrote: > is there something analogous to sys.platform that lets you get the version of > python you're using? sorry if the question is too see-spot-run. thanks if you > can help Check out sys.version and sys.version_info - are they what you're after? ChrisA -- https://mail.python.org/mailman/listinfo/python-list
how to get python version ?
hi is there something analogous to sys.platform that lets you get the version of python you're using? sorry if the question is too see-spot-run. thanks if you can help peace stm -- https://mail.python.org/mailman/listinfo/python-list
Re: how to get python version ?
[email protected] writes: > is there something analogous to sys.platform that lets you get the > version of python you're using? sorry if the question is too > see-spot-run. thanks if you can help The same ‘sys’ module provides many other ways to interrogate the running Python system https://docs.python.org/3/library/sys.html>. For the running version of Python, you want ‘sys.version_info’:: >>> import sys >>> sys.version '2.7.11 (default, Jan 11 2016, 21:04:40) \n[GCC 5.3.1 20160101]' >>> type(sys.version) >>> sys.version_info sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0) >>> type(sys.version_info) >>> sys.version_info > (3, 1) False >>> sys.version_info > (2, 5) True The ‘sys.version’ object is a human-readable string. If you actually want to do comparisons, use ‘sys.version_info’ for its much more fine-grained structure. -- \ “If you can't annoy somebody there is little point in writing.” | `\—Kingsley Amis | _o__) | Ben Finney -- https://mail.python.org/mailman/listinfo/python-list
Re: how to get python version ?
On Thursday, January 28, 2016 at 10:51:17 AM UTC+5:30, [email protected] wrote: > hi > > is there something analogous to sys.platform that lets you get the version of > python you're using? sorry if the question is too see-spot-run. thanks if you > can help > > peace > stm You want this?? https://docs.python.org/3.5/library/platform.html -- https://mail.python.org/mailman/listinfo/python-list
