any good midi tutorials?

2005-10-22 Thread malik
anybody know any good midi tutorials for python?
i am trying to make a realtime midi manipulation application.
-- 
http://mail.python.org/mailman/listinfo/python-list


PyEval_SetProfile usage ?

2012-07-06 Thread Salman Malik

Hi All,

I have used the Python's C-API to call some Python code in my c code and now I 
want to know how much time does my Python part of the program takes. I came 
across the PyEval_SetProfile API and am not sure how to use it. Do I need to 
write my own profiling function? 

Any pointer to examples or how to's will be much appreciated.

Thanks,
Salman-- 
http://mail.python.org/mailman/listinfo/python-list


RE: PyEval_SetProfile usage ?

2012-07-07 Thread Salman Malik

Thanks Thomas! I will try the timer code that you provided. I have tried 
profiling with just wrapping the python code with cprofiler's runctx but the 
problem is that my python code is sort of a packet parser and is called for 
each packet, but when I see the profiled results  it appears that the profile 
gets rewritten for each packet and I can't see the aggregate result: I see 1-2 
calls per function and each call is shown to have taken 0.00 time.

I have also tried valgrind's callgrind in conjunction with kcachegrind but it 
doesn't seem to show time measurement and by some reading I learned that it 
gives the CPU cycle's per function and not time. Any suggestions in this regard 
will also be very helpful.. Thanks!

Salman

> Date: Sat, 7 Jul 2012 11:50:05 +0200
> From: [email protected]
> To: [email protected]
> Subject: Re: PyEval_SetProfile usage ?
> 
> On 07/06/2012 11:40 PM, Salman Malik wrote:
> > Hi All,
> > 
> > I have used the Python's C-API to call some Python code in my c code and
> > now I want to know how much time does my Python part of the program
> > takes. I came across the PyEval_SetProfile API and am not sure how to
> > use it. Do I need to write my own profiling function?
> 
> You could have a look at the source code of the cProfile extension
> module. I assume it uses the feature.
> 
> In your case, what's wrong with simply measuring the time?
> 
> 
> /* variables. */
> unsigned long delta_usec;
> struct timeval t1, t2;
> 
> /* get start time */
> gettimeofday (&t1, NULL);
> 
> /* DO PYTHON STUFF */
> 
> /* get end time */
> gettimeofday (&t2, NULL);
> 
> /* delta? */
> delta_usec = (t2.tv_sec - t1.tv_sec) * 1000
>+ (signed)(t2.tv_usec - t1.tv_usec);
> 
> /* if your Python code is called multiple times, do this for each one,
>and (if you like) sum up the result. It's simpe enough, and you
>don't have to mess with profiling function.
>Alternatively, you could use a C profiler like Valgrind
> */
> -- 
> http://mail.python.org/mailman/listinfo/python-list
  -- 
http://mail.python.org/mailman/listinfo/python-list


Using pdb with greenlet?

2012-06-12 Thread Salman Malik

Hi,

I am sort of a newbie to Python ( have just started to use pdb). 

My problem is that I am debugging an application that uses greenlets and when I 
encounter something in code that spawns the coroutines or wait for an event, I 
lose control over the application (I mean that after that point I can no longer 
do 'n' or 's' on the code). Can anyone of you tell me how to tame greenlet with 
pdb, so that I can see step-by-step as to what event does a coroutine sees and 
how does it respond to it.

Any help would be highly appreciated.

Thanks,
Salman  
  -- 
http://mail.python.org/mailman/listinfo/python-list


Pyvenv puts both Python 2 and Python 3 in the same environment. Shocked!

2016-12-20 Thread Malik Rumi
I just created a new venv using pyvenv from a 2.7 install. Now I am shocked to 
see that I can get both 2.7 and 3.4 in this same venv:

(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python
Python 2.7.12 (default, Nov 19 2016, 06:48:10) 
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(memory) malikarumi@Tetuoan2:~/Projects/cannon/New2.7Projects/memory$ python3
Python 3.4.2 (default, Apr 17 2015, 18:47:05) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

I did not even know this was possible. Doesn’t that defeat the purpose? More to 
the point, how do I make sure I am using the right one? If I want the 
interpreter, that’s easy. But what happens when I want to install and use a 
program like Django? How do I control which interpreter Django uses? I’ve been 
through the official docs a couple of times today, but detailed explanations of 
pyvenv, let alone this dual version feature, have not been found. If you can 
point me to a good one, please do. Meanwhile...

I hoped maybe using different versions of pip would solve the problem, but pip2 
list and pip3 list are identical – hence, the very problem I thought venv’s 
were supposed to avoid. 

Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: the best online course

2016-07-09 Thread Malik Rumi
I want one of those "knuckle down and learn" classes. But even more than that, 
I want a class with a real teacher who is available to answer questions and 
explain things. I've done a lot of books and online video, but there's usually 
no help. If I search around long enough, I can often find an answer, but this 
is just way too fragmented for me. Where can I find classes like that - online 
- paid or free? Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


[no subject]

2015-12-15 Thread Malik Brahimi
Basically,  I'm trying to make an event based system with pywin32 that
handles spooled files that are to be printed. Users often print under the
impression that their document has yet to emerge from the printer when it
is in fact in queue. I'm creating a script that polls print jobs,  saves
them in a Mongo DB as needed, and prompts the user to reconsider another
print job for a duplicate document.

However,  I'm running into some problems distinguishing documents as unique
because the print job could have the same document name but the files could
be in different directories.  Additionally,  I have no idea how to
temporarily halt spooling until the user has confirmed their decision.

Does anyone have any idea how to distinguish documents as unique and how to
temporarily halt spooling as described?
-- 
https://mail.python.org/mailman/listinfo/python-list


Message Box

2015-12-28 Thread Malik Brahimi
Hey Guys,

I have an event driven script that prompts users as the events are
triggered with a message box. Is there anyway with any GUI toolkit to
create these dialogs simultaneously in the event that they coincide? I have
been trying everything, but I can't seem to get it right.

Malik
-- 
https://mail.python.org/mailman/listinfo/python-list


Handling Print Events

2016-02-07 Thread Malik Brahimi
Hello guys,

So basically, a print job (.SPL file) is generated during local spooling as
soon as a document is requested to print. I do NOT want to handle this
event.

I want to trigger a callback function as soon as a print job reaches a
print server regardless of whether it begins to immediately print there or
not. Essentially, even on a high volume network, I want to catch the even
in which the print job reaches the print server, not the event in which the
print job is initially created.

Is there anyway to do that with Python? I would also like to get the JobId
of said print job as this event is caught.

http://stackoverflow.com/questions/35228080/print-servers-and-triggering-callbacks
http://stackoverflow.com/questions/34519642/received-print-job-python

Thanks,

Malik
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Is anyone else unable to log into the bug tracker?

2015-02-26 Thread Malik Rumi
On Friday, January 9, 2015 at 7:49:09 PM UTC-6, Steven D'Aprano wrote:
> I'm having trouble logging into the bug tracker. Is anyone else having the
> same problem, that is, your user name and password worked earlier but
> doesn't work now?
> 
> http://bugs.python.org/
> 
> (Yes, I've checked the capslock key.)
> 
> 
> 
> Before I request a new password, I want to check whether it is me or
> everyone.
> 
> 
> -- 
> Steven



On Friday, January 9, 2015 at 7:49:09 PM UTC-6, Steven D'Aprano wrote:
> I'm having trouble logging into the bug tracker. Is anyone else having the
> same problem, that is, your user name and password worked earlier but
> doesn't work now?
> 
> http://bugs.python.org/
> 
> (Yes, I've checked the capslock key.)
> 
> 
> 
> Before I request a new password, I want to check whether it is me or
> everyone.
> 
> 
> -- 
> Steven



On Friday, January 9, 2015 at 7:49:09 PM UTC-6, Steven D'Aprano wrote:
> I'm having trouble logging into the bug tracker. Is anyone else having the
> same problem, that is, your user name and password worked earlier but
> doesn't work now?
> 
> http://bugs.python.org/
> 
> (Yes, I've checked the capslock key.)
> 
> 
> 
> Before I request a new password, I want to check whether it is me or
> everyone.
> 
> 
> -- 
> Steven

I am having this problem, even after I requested a new password. All I get is 
'invalid login'. How did you resolve? Thx.
-- 
https://mail.python.org/mailman/listinfo/python-list


Windows permission error, 64 bit, psycopg2, python 3.4.2

2015-02-26 Thread Malik Rumi
I am one of those struggling with compile issues with python on 64 bit windows. 
I have not been able to get the solutions mentioned on Stack Overflow to work 
because installing Windows SDK 7.1 fails for me. 

So I stumbled across a precompiled psycopg2, and that reported that it worked, 
but then I got two permission errors. Then I read that this was a bug in python 
(issue 14252) that had been fixed, but I don't think this is the same error. 
That one specifically refers to subprocess.py and I don't have that in my 
traceback.  I have v3.4.2. On top of everything else, despite requesting a new 
password, all I get from the big tracker is 'invalid login'. 

In any event, running "import psycopg2" returns 'import error, no module named 
psycopg2'.


Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\Semantic>pip install git+https://github.com/nwcell/psycopg2-windows.git
@win64-py34#egg=psycopg2
Downloading/unpacking psycopg2 from git+https://github.com/nwcell/psycopg2-windo
ws.git@win64-py34
  Cloning https://github.com/nwcell/psycopg2-windows.git (to win64-py34) to c:\u
sers\semantic\appdata\local\temp\pip_build_semantic\psycopg2
  Running setup.py (path:C:\Users\Semantic\AppData\Local\Temp\pip_build_Semantic
\psycopg2\setup.py) egg_info for package psycopg2
C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution opt
ion: 'summary'
  warnings.warn(msg)

Installing collected packages: psycopg2
  Running setup.py install for psycopg2
C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown distribution opt
ion: 'summary'
  warnings.warn(msg)

Successfully installed psycopg2
Cleaning up...
  Exception:
Traceback (most recent call last):
  File "C:\Python34\lib\shutil.py", line 370, in _rmtree_unsafe
os.unlink(fullname)
PermissionError: [WinError 5] Access is denied: 'C:\\Users\\Semantic\\AppData\\L
ocal\\Temp\\pip_build_Semantic\\psycopg2\\.git\\objects\\pack\\pack-be4d3da4a06b
4c9ec4c06040dbf6685eeccca068.idx'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in main
status = self.run(options, args)
  File "C:\Python34\lib\site-packages\pip\commands\install.py", line 302, in run

requirement_set.cleanup_files(bundle=self.bundle)
  File "C:\Python34\lib\site-packages\pip\req.py", line 1333, in cleanup_files
rmtree(dir)
  File "C:\Python34\lib\site-packages\pip\util.py", line 43, in rmtree
onerror=rmtree_errorhandler)
  File "C:\Python34\lib\shutil.py", line 477, in rmtree
return _rmtree_unsafe(path, onerror)
  File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
_rmtree_unsafe(fullname, onerror)
  File "C:\Python34\lib\shutil.py", line 372, in _rmtree_unsafe
onerror(os.unlink, fullname, sys.exc_info())
  File "C:\Python34\lib\site-packages\pip\util.py", line 53, in rmtree_errorhand
ler
(exctype is PermissionError and value.args[3] == 5) #python3.3
IndexError: tuple index out of range
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Windows permission error, 64 bit, psycopg2, python 3.4.2

2015-02-26 Thread Malik Rumi
On Thursday, February 26, 2015 at 2:55:07 PM UTC-6, Mark Lawrence wrote:
> On 26/02/2015 15:10, Malik Rumi wrote:
> > I am one of those struggling with compile issues with python on 64 bit 
> > windows. I have not been able to get the solutions mentioned on Stack 
> > Overflow to work because installing Windows SDK 7.1 fails for me.
> >
> > So I stumbled across a precompiled psycopg2, and that reported that it 
> > worked, but then I got two permission errors. Then I read that this was a 
> > bug in python (issue 14252) that had been fixed, but I don't think this is 
> > the same error. That one specifically refers to subprocess.py and I don't 
> > have that in my traceback.  I have v3.4.2. On top of everything else, 
> > despite requesting a new password, all I get from the big tracker is 
> > 'invalid login'.
> >
> > In any event, running "import psycopg2" returns 'import error, no module 
> > named psycopg2'.
> >
> >
> > Microsoft Windows [Version 6.3.9600]
> > (c) 2013 Microsoft Corporation. All rights reserved.
> >
> > C:\Users\Semantic>pip install 
> > git+https://github.com/nwcell/psycopg2-windows.git
> > @win64-py34#egg=psycopg2
> > Downloading/unpacking psycopg2 from 
> > git+https://github.com/nwcell/psycopg2-windo
> > ws.git@win64-py34
> >Cloning https://github.com/nwcell/psycopg2-windows.git (to win64-py34) 
> > to c:\u
> > sers\semantic\appdata\local\temp\pip_build_semantic\psycopg2
> >Running setup.py 
> > (path:C:\Users\Semantic\AppData\Local\Temp\pip_build_Semantic
> > \psycopg2\setup.py) egg_info for package psycopg2
> >  C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown 
> > distribution opt
> > ion: 'summary'
> >warnings.warn(msg)
> >
> > Installing collected packages: psycopg2
> >Running setup.py install for psycopg2
> >  C:\Python34\lib\distutils\dist.py:260: UserWarning: Unknown 
> > distribution opt
> > ion: 'summary'
> >warnings.warn(msg)
> >
> > Successfully installed psycopg2
> > Cleaning up...
> >Exception:
> > Traceback (most recent call last):
> >File "C:\Python34\lib\shutil.py", line 370, in _rmtree_unsafe
> >  os.unlink(fullname)
> > PermissionError: [WinError 5] Access is denied: 
> > 'C:\\Users\\Semantic\\AppData\\L
> > ocal\\Temp\\pip_build_Semantic\\psycopg2\\.git\\objects\\pack\\pack-be4d3da4a06b
> > 4c9ec4c06040dbf6685eeccca068.idx'
> >
> > During handling of the above exception, another exception occurred:
> >
> > Traceback (most recent call last):
> >File "C:\Python34\lib\site-packages\pip\basecommand.py", line 122, in 
> > main
> >  status = self.run(options, args)
> >File "C:\Python34\lib\site-packages\pip\commands\install.py", line 302, 
> > in run
> >
> >  requirement_set.cleanup_files(bundle=self.bundle)
> >File "C:\Python34\lib\site-packages\pip\req.py", line 1333, in 
> > cleanup_files
> >  rmtree(dir)
> >File "C:\Python34\lib\site-packages\pip\util.py", line 43, in rmtree
> >  onerror=rmtree_errorhandler)
> >File "C:\Python34\lib\shutil.py", line 477, in rmtree
> >  return _rmtree_unsafe(path, onerror)
> >File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
> >  _rmtree_unsafe(fullname, onerror)
> >File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
> >  _rmtree_unsafe(fullname, onerror)
> >File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
> >  _rmtree_unsafe(fullname, onerror)
> >File "C:\Python34\lib\shutil.py", line 367, in _rmtree_unsafe
> >  _rmtree_unsafe(fullname, onerror)
> >File "C:\Python34\lib\shutil.py", line 372, in _rmtree_unsafe
> >  onerror(os.unlink, fullname, sys.exc_info())
> >File "C:\Python34\lib\site-packages\pip\util.py", line 53, in 
> > rmtree_errorhand
> > ler
> >  (exctype is PermissionError and value.args[3] == 5) #python3.3
> > IndexError: tuple index out of range
> >
> 
> The above clearly shows "Successfully installed psycopg2" and that it's 
> a permission error on cleanup that's gone wrong, so what is there to 
> report on the bug tracker?
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

1. I did not mean t

Re: Is anyone else unable to log into the bug tracker?

2015-02-26 Thread Malik Rumi
On Thursday, February 26, 2015 at 10:49:19 AM UTC-6, Skip Montanaro wrote:
> I have not had problems, but I use the Google login (Open ID, I presume) 
> option.
> 
> 
> Skip

Ok, I got it. In short, capitalization (or not) matters. Thanks to all. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Path, strings, and lines

2015-06-12 Thread Malik Rumi
 I am trying to find a list of strings in a directory of files. Here is my code:

# -*- coding: utf-8 -*-
import os
import fileinput

s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')

with open('/home/malikarumi/Projects/P5/list_stories') as f:
lines = f.readlines()

for line in lines:
 for item in fileinput.input(s2):
 if line in item:
with open(line + '_list', 'a+') as l:
l.append(filename(), filelineno(), line)

And here is my error message:

In [44]: %run algo_e3.py
---
FileNotFoundError Traceback (most recent call last)
/home/malikarumi/Projects/Pipeline/4 Transforms/algo_e3.py in ()
  9 
 10 for line in lines:
---> 11  for item in fileinput.input(s2):
 12  if line in item:
 13 with open(line + '_list', 'a+') as l:

/usr/lib/python3.4/fileinput.py in __next__(self)
261 self._filelineno += 1
262 return line
--> 263 line = self.readline()
264 if not line:
265 raise StopIteration

/usr/lib/python3.4/fileinput.py in readline(self)
360 self._file = self._openhook(self._filename, 
self._mode)
361 else:
--> 362 self._file = open(self._filename, self._mode)
363 self._buffer = self._file.readlines(self._bufsize)
364 self._bufindex = 0

FileNotFoundError: [Errno 2] No such file or directory: 'THE LAND OF LOST TOYS~'

In trying to figure out what is wrong. I have run this same code, down to the 
'for line in lines', but ending with a print statement, and that works fine. I 
am also able to get it to print a list of the names of the files in s2. But as 
soon as I add 'for file in fileinput' things go sideways. Clearly the files 
exist, and I gave a full path. 

I see the pointers in the traceback, but I don't really grasp what they are 
telling me to do. 'line = self.readline()' and 'self._file = 
open(self._filename...' almost seems like fileinput is reading an instance of 
itself instead of s2.  I don't think that's right but it would explain why it 
can't find the file. 

I don't know what the tilde at the end of 'The Land of Lost Toys' is about. I 
don't think capitalization is an issue. All the files have all cap names to 
help me debug this from my list of strings. 

And if there is no such file or directory, how does Python know the correct 
name of at least this one file? My code does not give the names, all that is in 
the assigned variables. 

Thanks for your help. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Path, strings, and lines

2015-06-12 Thread Malik Rumi
On Friday, June 12, 2015 at 3:31:36 PM UTC-5, Ian wrote:
> On Fri, Jun 12, 2015 at 1:39 PM, Malik Rumi wrote:
> >  I am trying to find a list of strings in a directory of files. Here is my 
> > code:
> >
> > # -*- coding: utf-8 -*-
> > import os
> > import fileinput
> >
> > s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')
> 
> Note that the filenames that will be returned here are not fully
> qualified: you'll just get filename.txt, not
> /home/.../shortstories/filename.txt.
> 

Yes, that is what I want.

> > for line in lines:
> >  for item in fileinput.input(s2):
> 
> fileinput doesn't have the context of the directory that you listed
> above, so it's just going to look in the current directory.

Can you explain a little more what you mean by fileinput lacking the context of 
s4?

> 
> >  if line in item:
> > with open(line + '_list', 'a+') as l:
> > l.append(filename(), filelineno(), line)
> 
> Although it's not the problem at hand, I think you'll find that you
> need to qualify the filename() and filelineno() function calls with
> the fileinput module.

By 'qualify', do you mean something like 
l.append(fileinput.filename())?

> 
> > FileNotFoundError: [Errno 2] No such file or directory: 'THE LAND OF LOST 
> > TOYS~'
> 
> And here you can see that it's failing to find the file because it's
> looking in the wrong directory. You can use the os.path.join function
> to add the proper directory path to the filenames that you pass to
> fileinput.

I tried new code:

# -*- coding: utf-8 -*-
import os
import fileinput


os.path.join('/Projects/Pipeline/4 Transforms', '/Projects/P5/shortstories/')
s2 = os.listdir('/Projects/P5/shortstories/')
for item in fileinput.input(s2):
 if 'penelope' in item:
print(item)

But still got the same errors even though the assignment of the path variable 
seems to have worked:


In [51]: import os

In [52]: path = os.path.join('/Projects/Pipeline/4 Transforms', 
'/Projects/P5/shortstories')

In [53]: print(path)
/Projects/P5/shortstories

In [54]: %run algo_f3.py
---
FileNotFoundError Traceback (most recent call last)
/home/malikarumi/Projects/Pipeline/4 Transforms/algo_f3.py in ()
  5 
  6 os.path.join('/Projects/Pipeline/4 Transforms', 
'/Projects/P5/shortstories')
> 7 s2 = os.listdir('/Projects/P5/shortstories')
  8 for item in fileinput.input(s2):
  9  if 'penelope' in item:

FileNotFoundError: [Errno 2] No such file or directory: 
'/Projects/P5/shortstories'

In [55]: os.listdir(path)
---
FileNotFoundError Traceback (most recent call last)
 in ()
> 1 os.listdir(path)

FileNotFoundError: [Errno 2] No such file or directory: 
'/Projects/P5/shortstories'

In [56]: %run algo_f4.py
---
FileNotFoundError Traceback (most recent call last)
/home/malikarumi/Projects/Pipeline/4 Transforms/algo_f4.py in ()
  5 
  6 os.path.join('/Projects/Pipeline/4 Transforms', 
'/Projects/P5/shortstories/')
> 7 s2 = os.listdir('/Projects/P5/shortstories/')
  8 for item in fileinput.input(s2):
  9  if 'penelope' in item:

FileNotFoundError: [Errno 2] No such file or directory: 
'/Projects/P5/shortstories/'

Clearly, I don't understand os.path.join() although I have read about it and 
seen examples. In both https://www.youtube.com/watch?v=t5uRlE28F54  Python 
path.join, and listdir 
and in 
https://courses.cs.washington.edu/courses/cse140/13wi/file-interaction.html 
they are using a real, existing path to 'create' a path with os.join.path. So 
my immediate problem is that I don't see why that is necessary if they are 
dealing with an actual path. Why can't they just use the actual path? 

This is why I thought putting the absolute path in my code would solve this 
problem, but obviously not. Can you help me get a better grasp of how to use 
os.path.join, and why my refactored code still does not work? 
thanks.

> 
> > I don't know what the tilde at the end of 'The Land of Lost Toys' is about.
> 
> The trailing ~ is a convention used by Emacs (and possibly other
> editors) for files that it creates as backups.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Path, strings, and lines

2015-06-12 Thread Malik Rumi
On Friday, June 12, 2015 at 6:48:18 PM UTC-5, Chris Angelico wrote:
> On Sat, Jun 13, 2015 at 5:39 AM, Malik Rumi wrote:
> > for line in lines:
> >  for item in fileinput.input(s2):
> >  if line in item:
> > with open(line + '_list', 'a+') as l:
> > l.append(filename(), filelineno(), line)
> 
> Ian's already answered your actual question, but I'll make one
> separate comment. What you have here will open, append to, and close,
> the list file for every single line that you find. If you're expecting
> to find zero or very few lines, then that's fine, but if you expect
> you might find a lot, this will be extremely slow. Much more efficient
> would be to open the file once, and write to it every time - just
> switch around the nesting a bit:
> 
> with open(line + '_list', 'a+') as l:
>  for line in lines:
>  for item in fileinput.input(s2):
>  if line in item:
> l.append(filename(), filelineno(), line)
> 
> (Although you may want to rename your open file object, here; "l"
> isn't a very useful name at the best of times, so I'd be inclined to
> call it "log".)
> 
> ChrisA

Ok, I'll try that once I get out of my current thicket. ;-)
-- 
https://mail.python.org/mailman/listinfo/python-list


Struggling with os.path.join and fileinput (was 'Path, strings, and lines'

2015-06-15 Thread Malik Rumi
On Saturday, June 13, 2015 at 1:25:52 PM UTC-5, MRAB wrote:
> On 2015-06-13 05:48, Malik Rumi wrote:
> > On Friday, June 12, 2015 at 3:31:36 PM UTC-5, Ian wrote:
> >> On Fri, Jun 12, 2015 at 1:39 PM, Malik Rumi wrote:
> >> >  I am trying to find a list of strings in a directory of files. Here is 
> >> > my code:
> >> >
> >> > # -*- coding: utf-8 -*-
> >> > import os
> >> > import fileinput
> >> >
> >> > s2 = os.listdir('/home/malikarumi/Projects/P5/shortstories')
> >>
> >> Note that the filenames that will be returned here are not fully
> >> qualified: you'll just get filename.txt, not
> >> /home/.../shortstories/filename.txt.
> >>
> >
> > Yes, that is what I want.
> >
> >> > for line in lines:
> >> >  for item in fileinput.input(s2):
> >>
> >> fileinput doesn't have the context of the directory that you listed
> >> above, so it's just going to look in the current directory.
> >
> > Can you explain a little more what you mean by fileinput lacking the 
> > context of s4?
> >
> listdir returns the names of the files that are in the folder, not
> their paths.
> 
> If you give fileinput only the names of the files, it'll assume they're
> in the current folder (directory), which they (probably) aren't. You
> need to give fileinput the complete _paths_ of the files, not just
> their names.
> 
> >>
> >> >  if line in item:
> >> > with open(line + '_list', 'a+') as l:
> >> > l.append(filename(), filelineno(), line)
> >>
> >> Although it's not the problem at hand, I think you'll find that you
> >> need to qualify the filename() and filelineno() function calls with
> >> the fileinput module.
> >
> > By 'qualify', do you mean something like
> > l.append(fileinput.filename())?
> >
> >>
> >> > FileNotFoundError: [Errno 2] No such file or directory: 'THE LAND OF 
> >> > LOST TOYS~'
> >>
> >> And here you can see that it's failing to find the file because it's
> >> looking in the wrong directory. You can use the os.path.join function
> >> to add the proper directory path to the filenames that you pass to
> >> fileinput.
> >
> > I tried new code:
> >
> > # -*- coding: utf-8 -*-
> > import os
> > import fileinput
> >
> >
> os.join _returns its result.
> 
> > os.path.join('/Projects/Pipeline/4 Transforms', 
> > '/Projects/P5/shortstories/')
> > s2 = os.listdir('/Projects/P5/shortstories/')
> 
> At this point, s2 contains a list of _names_.
> 
> You pass those names to fileinput.input, but where are they? In which
> folder? It assumes they're in the current folder (directory), but
> they're not!
> 
> > for item in fileinput.input(s2):
> >   if 'penelope' in item:
> >  print(item)
> >
> > But still got the same errors even though the assignment of the path 
> > variable seems to have worked:
> >
> [snip]
> 
> Try this:
> 
>  filenames = os.listdir('/Projects/P5/shortstories/')
>  paths = [os.join('/Projects/P5/shortstories/', name) for name in names]
>  for item in fileinput.input(paths):

I have struggled with this for several hours and not made much progress. I was 
not sure if your 'names' variable was supposed to be the same as 'filenames'. 
Also, it should be 'os.path.join', not os.join. Anyway, I thought you had some 
good ideas so I worked with them but as I say I keep getting stuck at one 
particular point. Here is the current version of my code:

# -*- coding: utf-8 -*-
import os
import fileinput

path1 = os.path.join('Projects', 'P5', 'shortstories', '/')
path2 = os.path.join('Projects', 'P5')
targets = os.listdir(path1)
path3 = ((path1 + target) for target in targets)
path4 = os.path.join(path2,'list_stories')

with open(path4) as arrows:
quiver = arrows.readlines()


And here is my error message:

In [112]: %run algo_h1.py
---
FileNotFoundError Traceback (most recent call last)
/home/malikarumi/Projects/algo_h1.py in ()
  9 path4 = os.path.join(path2,'list_stories')
 10 
---> 11 with open(path4) as arrows:
 12 quiver = arrows.readlines()
 13  

Indian photographer denies affair with Lindsay Lohan!

2010-07-10 Thread asim malik
Speaking on the issue for the first time, Chaudhuri, over the phone
from New York, says, "They were completely distorted reports. We are
really good friends for more details www.bollywood789.blogspot.com
-- 
http://mail.python.org/mailman/listinfo/python-list


Regular Expressions, Speed, Python, and NFA

2017-04-14 Thread Malik Rumi
I am running some tests using the site regex101 to figure out the correct 
regexs to use for a project. I was surprised at how slow it was, constantly 
needing to increase the timeouts. I went Googling for a reason, and solution, 
and found Russ Cox’s article from 2007: 
https://swtch.com/~rsc/regexp/regexp1.html . I couldn’t understand why, if this 
was even remotely correct, we don’t use NFA in Python, which led me here:

https://groups.google.com/forum/#!msg/comp.lang.python/L1ZFI_R2hAo/C12Nf3patWIJ;context-place=forum/comp.lang.python
 where all of these issues were addressed. Unfortunately, this is also from 
2007. 

BTW, John Machin in one of his replies cites Navarro’s paper, but that link is 
broken. Navarro’s work can now be found at 
http://citeseer.ist.psu.edu/viewdoc/download?doi=10.1.1.21.3112&rep=rep1&type=pdf
 But be forewarned, it is 68 pages of dense reading. I am not a computer 
science major. I am not new to Python, but I don’t think I’m qualified to take 
on the idea of creating a new NFA module for Python.  

>Getting back to the "It would be nice ..." bit: yes, it would be nice
>to have even more smarts in re, but who's going to do it? It's not a
>"rainy Sunday afternoon" job :-)
>Cheers,
>John
-
>Well, just as an idea, there is a portable C library for this at 
>http://laurikari.net/tre/ released under LGPL.  If one is willing to 
>give up PCRE extensions for speed, it might be worth the work to 
>wrap this library using SWIG.
>Kirk Sluder

(BTW, this link is also old. TRE is now at https://github.com/laurikari/tre/ )

I am not a computer science major. I am not new to Python, but I don’t think 
I’m qualified to take on the idea of creating a new NFA module for Python.  Nor 
am I entirely sure I want to try something new (to me) like TRE. 

Most threads related to this topic are older than 2007. I did find this 
https://groups.google.com/forum/#!searchin/comp.lang.python/regex$20speed%7Csort:relevance/comp.lang.python/O7rUwVoD2t0/NYAQM0mUX7sJ
 from 2011 but I did not do an exhaustive search. 

The bottom line is I wanted to know if anything has changed since 2007, and if 
there is a) any hope for improving regex speeds in Python, or b) some 3rd party 
module/library that is already out there and solves this problem? Or should I 
just take this advice?

>The cheap way in terms of programmer time is to pipe out to grep or
>awk on this one.
>Kirk Sluder

Thanks. 
-- 
https://mail.python.org/mailman/listinfo/python-list