sharon stone paris hilton

2007-04-22 Thread S S
sharon  stone paris hilton 



www.alphasearch.at
www.alphasearch.be 
www.alphasearch.it
www.alphasearch.info
www.alphasearch.gr 
www.alphasearch.es 
www.alphasearch.se
www.alphasearch.dk -- 
http://mail.python.org/mailman/listinfo/python-list

Lex Python

2005-05-17 Thread s
I am using bumblebee software PARSER GENERATOR to make a C file from LEX 
regular definitions.
I want to compile that C file with VS .NET but I have problems.
I am working this for Python regular definitions.
Does somebody know how to configure a project to work? Or maybe somone havde 
done all this and can hel me in that way.I need this help soon as possible.
Thanks


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


hai

2010-10-19 Thread Viji Kumar S S
 http://123maza.com/35/demand120/
-- 
http://mail.python.org/mailman/listinfo/python-list


Distutils beginner question - windows

2011-06-03 Thread Seb S

Hi all,

Just a quick question , I have a simple script I want to convert into a windows 
installer and give to some friends. 
I had a look at http://docs.python.org/distutils/introduction.html  and wrote 
this setup script:


#!/usr/bin/env python

from distutils.core import setup

setup(name="C:\data\Sendmailmsg.py",
  version='1.0',
  description='Python Distribution Utilities',
  author='Sebas929',
  author_email=' ',
  url=' ',
  py_modules=['urllib','smtplib'],
 )


I tried to run this  - "C:\Data\Setup.py" bdist_wininst  - in a cmd prompt.
C:\Data\ contains my script Sendmailmsg.py and Setup.py
I am getting the error :

file urllib.py (for module urllib) not found
file smtplib.py (for module smtplib) not found
file urllib.py (for module urllib) not found
file smtplib.py (for module smtplib) not found

warning: install_lib: 'build\lib' does not exist -- no Python modules to install

This creates an installer which crashes when I use it.

I have a few questions:
How can I fix this error ? 

Can I use '.\myscript.py' in the name parameter to make it look in the same 
directory as setup.py? 

When I have it as an installer what happens? When I install it will there be 
something you can click which will run the script?

I have never tried this before so I am probably missing something obvious, 
thanks in advance for any help.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: integer to binary 0-padded

2011-06-17 Thread John S
On Jun 15, 9:33 am, Olivier LEMAIRE 
wrote:
> You're right, I use Python 2.6.6

This works great in 2.6.5 and later (and probably earlier). You just
have to number your placeholders. The first set of braces formats i
(your value), the second set specifies the field with (i.e., 8):

>>> for i in xrange(10):
... print "{0:0{1}b}".format(i,8)
...

0001
0010
0011
0100
0101
0110
0111
1000
1001
-- 
http://mail.python.org/mailman/listinfo/python-list


WindowsError: exception: access violation

2011-07-21 Thread Sathish S
Hi Ppl,

 I have been trying to call a C DLL built in GCC with cygwin and Eclipse IDE
from python. Since this DLL was built using cygwin it had the following two
DLL's as dependency. cygwin1.dll and cyggcc_s-1.dll

I'm calling the cygwin_dll_init method in the cygwin1.dll before accessing
my DLL. When I call one of the methods within my DLL I get the WindowsError:
exception: access violation... error

the functions prototype is like: int function(char *, char *) I'm calling
the function as: DLL = cdll.LoadLibrary (DLL_NAME) print
DLL.function(c_char_p("string1"),c_char_p("string2)")

This error is not consistent with all the stations. I occurs consistently in
many XP machines, while in Windows 7, this occurs once in a while. In Win 7
in starts up a Pythonw.exe process when calling function successfully. I'm
not sure why this error occurs. Any help ??

Thanks,

Sathish
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: WindowsError: exception: access violation

2011-07-21 Thread Sathish S
Benjamin thanks for replying. i'm not using the python that comes with
cygwin. Its the regular python 2.7.2
To add more info
I'm opening up a zip file within the DLL. The zip file is located in the
same directory.
arg1 is the file name
arg2 is zip password

Thanks,
Sathish


On Fri, Jul 22, 2011 at 7:47 AM, Benjamin Kaplan
wrote:

> On Thu, Jul 21, 2011 at 6:42 PM, Sathish S 
> wrote:
> > Hi Ppl,
> >
> >  I have been trying to call a C DLL built in GCC with cygwin and Eclipse
> IDE
> > from python. Since this DLL was built using cygwin it had the following
> two
> > DLL's as dependency. cygwin1.dll and cyggcc_s-1.dll
> >
> > I'm calling the cygwin_dll_init method in the cygwin1.dll before
> accessing
> > my DLL. When I call one of the methods within my DLL I get the
> WindowsError:
> > exception: access violation... error
> >
> > the functions prototype is like: int function(char *, char *) I'm calling
> > the function as: DLL = cdll.LoadLibrary (DLL_NAME) print
> > DLL.function(c_char_p("string1"),c_char_p("string2)")
> >
> > This error is not consistent with all the stations. I occurs consistently
> in
> > many XP machines, while in Windows 7, this occurs once in a while. In Win
> 7
> > in starts up a Pythonw.exe process when calling function successfully.
> I'm
> > not sure why this error occurs. Any help ??
> >
>
> An access violation is what is usually referred to as a seg fault. It
> means something isn't getting initialized properly. Are you using a
> Cygwin build of Python? Trying to mix Cygwin with normal Windows
> programs doesn't usually work very well.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Calling Script from Command line not working

2011-08-29 Thread Sathish S
Hi Ppl,

We created a DLL using cygwin and have written a class based python module
for the same. We have created a sample script for the class based python
module, that creates an object of the class and calls various methods in the
class. This Test script works fine while I run it from IDLE. However when I
run it from command prompt it either hangs or just returns without executing
the functions. When it returns I do not get a error trace.

When I tried to findout where exactly the issue is happening. the issue
occurs when I try to call the *cygwin_dll_init* method of the cygwin1.dll .
This cygwin1.dll is actualy a dependency to the DLL we have built. So we
have to load this DLL and call this *cygwin_dll_init* method before loading
my DLL.


cyg = cdll.LoadLibrary("cygwin1.dll")
cyg.*cygwin_dll_init() #hangs or returns here*
*mydll=**cdll.LoadLibrary("my.dll")
*
*mydll.func1()*
*
*
*I'm trying to understand what exactly is the difference, when we call it
IDLE and when we call it from command prompt using the python command. I
will have to get the script working from command prompt as well.*
*
*
Thanks,
Sathish
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Script from Command line not working

2011-09-01 Thread Sathish S
Hey Gabriel,
Thanks a lot for replying. I was able to run this python script from
console/command prompt using cygwin python. I'm not sure whats the
difference between these two versions of python. But it seems to be working.
Searching theough the web i found that having cygwin1.dll could be causing
this issue. So I'm trying to build my DLL using MinGW which will not create
an dependecy DLL's. But I'm stuck up with few more issue in porting few
functions to MinGW.

I'm using Python2.7 and Cygwin Python 2.6.5

*Reply to your comments:*

** why do you initialize cygwin1.dll in Python? If it's a dependency of
my.dll, it might be better to load and initialize it there.*
Yes, cygwin1.dll is actually a dependency to my.dll. hence I'm loading it
and initializing it
** for this function prototype: void cygwin_dll_init(void);*
*you should declare it using:*
I'm doing this as you said. But didn't mention it in my mail

hCyg = cdll.LoadLibrary(CygWinDLL_Name)
hCyg = CDLL(CygWinDLL_Name)
Prototype_Cyg = CFUNCTYPE(c_void_p)
Init = Prototype_Cyg (("cygwin_dll_init", hCyg))
Init.restype = c_void_p
Init()

Thanks,
Sathish


On Fri, Sep 2, 2011 at 7:56 AM, Gabriel Genellina wrote:

> En Mon, 29 Aug 2011 07:40:06 -0300, Sathish S 
> escribió:
>
>
>  We created a DLL using cygwin and have written a class based python module
>> for the same. We have created a sample script for the class based python
>> module, that creates an object of the class and calls various methods in
>> the
>> class. This Test script works fine while I run it from IDLE. However when
>> I
>> run it from command prompt it either hangs or just returns without
>> executing
>> the functions. When it returns I do not get a error trace.
>>
>> When I tried to findout where exactly the issue is happening. the issue
>> occurs when I try to call the *cygwin_dll_init* method of the cygwin1.dll
>> .
>> This cygwin1.dll is actualy a dependency to the DLL we have built. So we
>> have to load this DLL and call this *cygwin_dll_init* method before
>> loading
>> my DLL.
>>
>>
>> cyg = cdll.LoadLibrary("cygwin1.dll"**)
>> cyg.cygwin_dll_init() #hangs or returns here
>> mydll=cdll.LoadLibrary("my.**dll")
>> mydll.func1()
>> I'm trying to understand what exactly is the difference, when we call it
>> IDLE and when we call it from command prompt using the python command. I
>> will have to get the script working from command prompt as well.
>>
>
> A few comments:
>
> * why do you initialize cygwin1.dll in Python? If it's a dependency of
> my.dll, it might be better to load and initialize it there.
>
> * for this function prototype: void cygwin_dll_init(void);
> you should declare it using:
>
>
> cyg = cdll.LoadLibrary("cygwin1.dll"**)
> cyg.restype = None
>
> cyg.cygwin_dll_init() #hangs or returns here
> ...
>
> Anyway, I don't see why a console application would fail but not inside
> IDLE.
>
> --
> Gabriel Genellina
>
> --
> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Calling Script from Command line not working

2011-09-01 Thread Sathish S
One more thing I observed is, while running the script from IDLE it launches
a seperate process of pythonw.exe and I could see this console window poping
up. However while running it from command prompt this does not happens. I
was wondering if the command prompt way of calling the script is not able to
launch this new process, that why it could be hanging.

BTW I'm still trying to get the script running using Python 2.7 from the
command prompt.

Thanks,
Sathish


On Fri, Sep 2, 2011 at 11:47 AM, Sathish S  wrote:

> Hey Gabriel,
> Thanks a lot for replying. I was able to run this python script from
> console/command prompt using cygwin python. I'm not sure whats the
> difference between these two versions of python. But it seems to be working.
> Searching theough the web i found that having cygwin1.dll could be causing
> this issue. So I'm trying to build my DLL using MinGW which will not create
> an dependecy DLL's. But I'm stuck up with few more issue in porting few
> functions to MinGW.
>
> I'm using Python2.7 and Cygwin Python 2.6.5
>
> *Reply to your comments:*
>
>
> ** why do you initialize cygwin1.dll in Python? If it's a dependency of
> my.dll, it might be better to load and initialize it there.*
> Yes, cygwin1.dll is actually a dependency to my.dll. hence I'm loading it
> and initializing it
>
> ** for this function prototype: void cygwin_dll_init(void);*
> *you should declare it using:*
> I'm doing this as you said. But didn't mention it in my mail
>
> hCyg = cdll.LoadLibrary(CygWinDLL_Name)
> hCyg = CDLL(CygWinDLL_Name)
> Prototype_Cyg = CFUNCTYPE(c_void_p)
> Init = Prototype_Cyg (("cygwin_dll_init", hCyg))
> Init.restype = c_void_p
> Init()
>
> Thanks,
> Sathish
>
>
>
> On Fri, Sep 2, 2011 at 7:56 AM, Gabriel Genellina 
> wrote:
>
>> En Mon, 29 Aug 2011 07:40:06 -0300, Sathish S 
>> escribió:
>>
>>
>>  We created a DLL using cygwin and have written a class based python
>>> module
>>> for the same. We have created a sample script for the class based python
>>> module, that creates an object of the class and calls various methods in
>>> the
>>> class. This Test script works fine while I run it from IDLE. However when
>>> I
>>> run it from command prompt it either hangs or just returns without
>>> executing
>>> the functions. When it returns I do not get a error trace.
>>>
>>> When I tried to findout where exactly the issue is happening. the issue
>>> occurs when I try to call the *cygwin_dll_init* method of the cygwin1.dll
>>> .
>>> This cygwin1.dll is actualy a dependency to the DLL we have built. So we
>>> have to load this DLL and call this *cygwin_dll_init* method before
>>> loading
>>> my DLL.
>>>
>>>
>>> cyg = cdll.LoadLibrary("cygwin1.dll"**)
>>> cyg.cygwin_dll_init() #hangs or returns here
>>> mydll=cdll.LoadLibrary("my.**dll")
>>> mydll.func1()
>>> I'm trying to understand what exactly is the difference, when we call it
>>> IDLE and when we call it from command prompt using the python command. I
>>> will have to get the script working from command prompt as well.
>>>
>>
>> A few comments:
>>
>> * why do you initialize cygwin1.dll in Python? If it's a dependency of
>> my.dll, it might be better to load and initialize it there.
>>
>> * for this function prototype: void cygwin_dll_init(void);
>> you should declare it using:
>>
>>
>> cyg = cdll.LoadLibrary("cygwin1.dll"**)
>> cyg.restype = None
>>
>> cyg.cygwin_dll_init() #hangs or returns here
>> ...
>>
>> Anyway, I don't see why a console application would fail but not inside
>> IDLE.
>>
>> --
>> Gabriel Genellina
>>
>> --
>> http://mail.python.org/**mailman/listinfo/python-list<http://mail.python.org/mailman/listinfo/python-list>
>>
>
>
-- 
http://mail.python.org/mailman/listinfo/python-list


Unload a DLL

2011-02-24 Thread Sathish S
Hi Ppl,

I'm loading a dll using the *cdll.LoadLibrary *function. How can I release
the dll after I'm done with it. Are there any functions to do this.

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


Re: pattern matching

2011-02-24 Thread John S
On Feb 23, 9:11 pm, monkeys paw  wrote:
> if I have a string such as '01/12/2011' and i want
> to reformat it as '20110112', how do i pull out the components
> of the string and reformat them into a DDMM format?
>
> I have:
>
> import re
>
> test = re.compile('\d\d\/')
> f = open('test.html')  # This file contains the html dates
> for line in f:
>      if test.search(line):
>          # I need to pull the date components here
What you need are parentheses, which capture part of the text you're
matching. Each set of parentheses creates a "group". To get to these
groups, you need the match object which is returned by re.search.
Group 0 is the entire match, group 1 is the contents of the first set
of parentheses, and so forth. If the regex does not match, then
re.search returns None.


DATA FILE (test.html):

David02/19/1967
Susan05/23/1948
Clare09/22/1952
BP08/27/1990
Roger12/19/1954



CODE:
import re
rx_test = re.compile(r'(\d{2})/(\d{2})/(\d{4})')

f = open('test.html')
for line in f:
m = rx_test.search(line)
if m:
new_date = m.group(3) + m.group(1) + m.group(2)
print "raw text: ",m.group(0)
print "new date: ",new_date
print

OUTPUT:
raw text:  02/19/1967
new date:  19670219

raw text:  05/23/1948
new date:  19480523

raw text:  09/22/1952
new date:  19520922

raw text:  08/27/1990
new date:  19900827

raw text:  12/19/1954
new date:  19541219



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


RE: CentOS 5.5 x86_64 rpmbuild from source

2011-03-08 Thread William S .
I will answer myself. For those interested, because rpm will break the
dependencies on the OS,  you can install 2.7 with a simple bash script:
http://willsani.com/2011/03/02/centos-5-5-x86_64-install-python-2-7/ 

Regards,
Will 

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


Re: .Well, ok, I will try some of that. But I am running window 7, not Linux.

2011-04-22 Thread P S
I did a little writeup for setting PyVISA up in Windows. It's not exactly 
polished, but it can get you through the difficult bits. If you need any 
additional help, leave comments/questions on my blog.

http://psonghi.wordpress.com/2011/03/29/pyvisa-setup-in-windows/

> On Friday, April 01, 2011 11:29 AM Manatee wrote:

> I have unpacked the PyVISA files into the Python/lib/site-packages dir
> and from the IDLE GUI I get and error
> 
> import visa
> 
> Traceback (most recent call last):
> File "", line 1, in 
> import visa
> ImportError: No module named visa
> 
> 
> 
> There must be more to just putting the files in the correct directory.
> Need help configuring PyVISA to work.
> My ultimate goal is to control electronic instruments with Python
> through visa.


>> On Friday, April 01, 2011 2:05 PM GüntherDietrich wrote:

>> Yes, there is more:
>> 
>> - DON'T unpack the files into any site-packages folder. If you already
>> have done it, remove them.
>> - Unpack the PyVISA archive to any other folder.
>> - On the command line, change into the PyVISA folder. There you should
>> find - among others - the two files setup.py and setup.cfg (at least
>> if you use PyVISA-1.3.tar.gz).
>> - Now, it depends on what variant of python you use and want to install
>> PyVISA for and on the configuration of your PYTHONPATH rsp. sys.path
>> and the folders they point to.
>> You can simply try: 'sudo python ./setup install'
>> If you are lucky, that is it. If not, you have to decide, where the
>> installation script has to put the files to. For example, for my
>> python 2.6, I chose
>> '/Library/Frameworks/Python.framework/Versions/2.6/'. In this path,
>> there is a folder 'lib/site-packages', which is pointed to by
>> sys.path, and where .pth files are evaluated.
>> - Edit the file setup.cfg. Near the end, in section '[install]', you will
>> find the line 'prefix=/usr'. Replace the '/usr' by your chosen path.
>> - Save the file and retry the install (see above).
>> 
>> 
>> 
>> Best regards,
>> 
>> G??nther


>>> On Friday, April 01, 2011 3:40 PM Manatee wrote:

>>> .
>>> 
>>> Well, ok, I will try some of that. But I am running window 7, not Linux.
>>> The "sudo" command sounds like Linux.



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


SEE KAREENA KAPOOR BOLLYWOOD HOT ACTRESS BOOBS PRESSED IN SHOPPING MALL

2011-05-15 Thread charmi s
SEE KAREENA KAPOOR BOLLYWOOD HOT ACTRESS BOOBS PRESSED IN SHOPPING
MALL
At http://hollypops.Co.CC

Due to GOOGLE security risks, i have hidden the videos in an image.
in that website on Right side  below search box click on image
and watch videos in all angles.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Weird problem matching with REs

2011-05-29 Thread John S
On May 29, 10:35 am, Andrew Berg  wrote:
> On 2011.05.29 09:18 AM, Steven D'Aprano wrote:> >> What makes you think it 
> shouldn't match?
>
> > > AFAIK, dots aren't supposed to match carriage returns or any other
> > > whitespace characters.
>
> I got things mixed up there (was thinking whitespace instead of
> newlines), but I thought dots aren't supposed to match '\r' (carriage
> return). Why is '\r' not considered a newline character?

Dots don't match end-of-line-for-your-current-OS is how I think of
it.

While I almost usually nod my head at Steven D'Aprano's comments, in
this case I have to say that if you just want to grab something from a
chunk of HTML, full-blown HTML parsers are overkill. True, malformed
HTML can throw you off, but they can also throw a parser off.

I could not make your regex work on my Linux box with Python 2.6.

In your case, and because x264 might change their HTML, I suggest the
following code, which works great on my system.YMMV. I changed your
newline matches to use \s and put some capturing parentheses around
the date, so you could grab it.

>>> import urllib2
>>> import re
>>>
>>> content = urllib2.urlopen("http://x264.nl/x264_main.php";).read()
>>>
>>> rx_x264version= 
>>> re.compile(r"http://x264\.nl/x264/64bit/8bit_depth/revision\s*(\d{4})\s*/x264\s*\.exe")
>>>
>>> m = rx_x264version.search(content)
>>> if m:
... print m.group(1)
...
1995
>>>


\s is your friend -- matches space, tab, newline, or carriage return.
\s* says match 0 or more spaces, which is what's needed here in case
the web site decides to *not* put whitespace in the middle of a URL...

As Steven said, when you want match a dot, it needs to be escaped,
although it will work by accident much of the time. Also, be sure to
use a raw string when composing REs, so you don't run into backslash
issues.

HTH,
John Strickler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Weird problem matching with REs

2011-05-29 Thread John S
On May 29, 12:16 pm, Andrew Berg  wrote:
>
> I've been meaning to learn how to use parenthesis groups.
> > Also, be sure to
> > use a raw string when composing REs, so you don't run into backslash
> > issues.
>
> How would I do that when grabbing strings from a config file (via the
> configparser module)? Or rather, if I have a predefined variable
> containing a string, how do change it into a raw string?
When reading the RE from a file it's not an issue. Only literal
strings can be raw. If the data is in a file, the data will not be
parsed by the Python interpreter. This was just a general warning to
anyone working with REs. It didn't apply in this case.

--john strickler
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Why no '|' operator for dict?

2018-02-05 Thread Maxime S
2018-02-05 9:14 GMT+01:00 Ian Kelly :
> On Mon, Feb 5, 2018 at 12:35 AM, Frank Millman  wrote:
>> 2. Is there a better way to do what I want?
>
> The dict.items() view is explicitly set-like and can be unioned, so
> you can do this:
>
> py> dict(d1.items() | d2.items())
>
> As to the question of which value will appear in the union in the case
> of duplicate keys, it will be whichever one arbitrarily appears later
> in the iteration order of the intermediate set.

Since Python 3.5, it is also possible to use PEP448 generalized unpacking:

dict([*d1.items(), *d2.items()])

In which case the value that appears in case of duplicate keys is
better defined, it will be the one appearing in the last dictionnary.
-- 
https://mail.python.org/mailman/listinfo/python-list


How to loop over a text file (to remove tags and normalize) using Python

2021-03-09 Thread S Monzur
Dear List,

Newbie here. I am trying to loop over a text file to remove html tags,
punctuation marks, stopwords. I have already used Beautiful Soup (Python v
3.8.3) to scrape the text (newspaper articles) from the site. It returns a
list that I saved as a file. However, I am not sure how to use a loop in
order to process all the items in the text file.

In the code below I have used listfilereduced.text(containing data from one
news article, link to listfilereduced.txt here
),
however I would like to run this code on listfile.text(containing data from
multiple articles, link to listfile.text

).


Any help would be greatly appreciated!

P.S. The text is in a Non-English script, but the tags are all in English.


#The code below is for a textfile containing just one item. I am not sure
how to tweak this to make it run for listfile.text (which contains raw data
from multiple articles) with open('listfilereduced.txt', 'r',
encoding='utf8') as my_file: rawData = my_file.read() print(rawData)
#Separating body text from other data articleStart = rawData.find("") articleData =
rawData[:articleStart] articleBody = rawData[articleStart:]
print(articleData) print("***") print(articleBody) print("***")
#First, I define a function to strip tags from the body text def
stripTags(pageContents): insideTag = 0 text = '' for char in pageContents:
if char == '<': insideTag = 1 elif (insideTag == 1 and char == '>'):
insideTag = 0 elif insideTag == 1: continue else: text += char return text
#Calling the function articleBodyText = stripTags(articleBody)
print(articleBodyText) ##Isolating article title and publication date
TitleEndLoc = articleData.find("") dateStartLoc =
articleData.find("")
dateEndLoc=articleData.find("") titleString =
articleData[:TitleEndLoc] dateString = articleData[dateStartLoc:dateEndLoc]
##Call stripTags to clean articleTitle= stripTags(titleString) articleDate
= stripTags(dateString) print(articleTitle) print(articleDate) #Cleaning
the date a bit more startLocDate = articleDate.find(":") endLocDate =
articleDate.find(",") articleDateClean =
articleDate[startLocDate+2:endLocDate] print(articleDateClean) #save all
this data to a dictionary that saves the title, data and the body text
PAloTextDict = {"Title": articleTitle, "Date": articleDateClean, "Text":
articleBodyText} print(PAloTextDict) #Normalize text by: #1. Splitting
paragraphs of text into lists of words articleBodyWordList =
articleBodyText.split() print(articleBodyWordList) #2.Removing punctuation
and stopwords from bnlp.corpus import stopwords, punctuations #A. Remove
punctuation first listNoPunct = [] for word in articleBodyWordList: for
mark in punctuations: word=word.replace(mark, '') listNoPunct.append(word)
print(listNoPunct) #B. removing stopwords banglastopwords = stopwords()
print(banglastopwords) cleanList=[] for word in listNoPunct: if word in
banglastopwords: continue else: cleanList.append(word) print(cleanList)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to loop over a text file (to remove tags and normalize) using Python

2021-03-09 Thread S Monzur
Thank you and apologies! I did not realize how jumbled it was at the
receiver's end.

The code is now at this site :  https://pastebin.com/wSi2xzBh

I'm basically trying to do a few things with my code-

   1.

   Extract 3 strings from the text- title, date and main text
   2.

   Remove all tags afterwards
   3.

   Save in a dictionary, with three keys- title, date and bodytext.
   4.

   Remove punctuation and stopwords (I've used a user generated function
   for that).

I've been able to do all of these steps for the file ListFileReduced
<https://drive.google.com/file/d/1ojwN4u8cmh_nUoMJpdZ5ObaGW5URYYj3/view?usp=sharing>,
as shown in the code (although it's clunky).

But, I would like to be able to do it for the other text file: ListFile
<https://drive.google.com/file/d/1V3s8w8a3NQvex91EdOhdC9rQtCAOElpm/view?usp=sharing>
which has more articles. I used BeautifulSoup to scrape the data from the
website, and then generated a list that I saved as a text file.


Best,

Monzur

On Wed, Mar 10, 2021 at 4:00 AM Dan Ciprus (dciprus) 
wrote:

> If you could utilized pastebin or similar site to show your code, it would
> help
> tremendously since it's an unindented mess now and can not be read easily.
>
> On Wed, Mar 10, 2021 at 03:07:14AM +0600, S Monzur wrote:
> >Dear List,
> >
> >Newbie here. I am trying to loop over a text file to remove html tags,
> >punctuation marks, stopwords. I have already used Beautiful Soup (Python v
> >3.8.3) to scrape the text (newspaper articles) from the site. It returns a
> >list that I saved as a file. However, I am not sure how to use a loop in
> >order to process all the items in the text file.
> >
> >In the code below I have used listfilereduced.text(containing data from
> one
> >news article, link to listfilereduced.txt here
> ><
> https://drive.google.com/file/d/1ojwN4u8cmh_nUoMJpdZ5ObaGW5URYYj3/view?usp=sharing
> >),
> >however I would like to run this code on listfile.text(containing data
> from
> >multiple articles, link to listfile.text
> ><
> https://drive.google.com/file/d/1V3s8w8a3NQvex91EdOhdC9rQtCAOElpm/view?usp=sharing
> >
> >).
> >
> >
> >Any help would be greatly appreciated!
> >
> >P.S. The text is in a Non-English script, but the tags are all in English.
> >
> >
> >#The code below is for a textfile containing just one item. I am not sure
> >how to tweak this to make it run for listfile.text (which contains raw
> data
> >from multiple articles) with open('listfilereduced.txt', 'r',
> >encoding='utf8') as my_file: rawData = my_file.read() print(rawData)
> >#Separating body text from other data articleStart = rawData.find(" >class=\"story-element story-element-text\">") articleData =
> >rawData[:articleStart] articleBody = rawData[articleStart:]
> >print(articleData) print("***") print(articleBody) print("***")
> >#First, I define a function to strip tags from the body text def
> >stripTags(pageContents): insideTag = 0 text = '' for char in pageContents:
> >if char == '<': insideTag = 1 elif (insideTag == 1 and char == '>'):
> >insideTag = 0 elif insideTag == 1: continue else: text += char return text
> >#Calling the function articleBodyText = stripTags(articleBody)
> >print(articleBodyText) ##Isolating article title and publication date
> >TitleEndLoc = articleData.find("") dateStartLoc =
> >articleData.find(" >class=\"storyPageMetaData-m__publish-time__19bdV\">")
> >dateEndLoc=articleData.find(" >storyPageMetaDataIcons-m__icons__3E4Xg\">") titleString =
> >articleData[:TitleEndLoc] dateString =
> articleData[dateStartLoc:dateEndLoc]
> >##Call stripTags to clean articleTitle= stripTags(titleString) articleDate
> >= stripTags(dateString) print(articleTitle) print(articleDate) #Cleaning
> >the date a bit more startLocDate = articleDate.find(":") endLocDate =
> >articleDate.find(",") articleDateClean =
> >articleDate[startLocDate+2:endLocDate] print(articleDateClean) #save all
> >this data to a dictionary that saves the title, data and the body text
> >PAloTextDict = {"Title": articleTitle, "Date": articleDateClean, "Text":
> >articleBodyText} print(PAloTextDict) #Normalize text by: #1. Splitting
> >paragraphs of text into lists of words articleBodyWordList =
> >articleBodyText.split() print(articleBodyWordList) #2.Removing punctuation
> >and stopwords from bnlp.corpus import stopwords, punctuations #A. Remove
> >punctuation first listNoPun

Re: How to loop over a text file (to remove tags and normalize) using Python

2021-03-09 Thread S Monzur
Thanks! I ended up using beautiful soup to remove the html tags and create
three lists (titles of article, publications dates, main body) but am still
facing a problem where the list is not properly storing the main body.
There is something wrong with my code for that section, and any comment
would be really helpful!

 ListFile Text
<https://drive.google.com/file/d/1V3s8w8a3NQvex91EdOhdC9rQtCAOElpm/view?usp=sharing>
BeautifulSoup code for removing tags <https://pastebin.com/qvbVMUGD>


On Wed, Mar 10, 2021 at 4:32 AM Dan Ciprus (dciprus) 
wrote:

> No problem, list just converts everything into plain/txt which is GREAT !
> :-)
>
> So without digging deeply into what you need to do: I am assuming that
> your
> input contains html tags. Why don't you utilize lib like:
> https://pypi.org/project/beautifulsoup4/ instead of doing harakiri with
> parsing
> data without using regex ? Just a hint ..
>
> On Wed, Mar 10, 2021 at 04:22:19AM +0600, S Monzur wrote:
> >   Thank you and apologies! I did not realize how jumbled it was at the
> >   receiver's end.
> >   The code is now at this site :  [1]https://pastebin.com/wSi2xzBh
> >   I'm basically trying to do a few things with my code-
> >
> >1. Extract 3 strings from the text- title, date and main text
> >
> >2. Remove all tags afterwards
> >
> >3. Save in a dictionary, with three keys- title, date and bodytext.
> >
> >4. Remove punctuation and stopwords (I've used a user generated
> function
> >   for that).
> >
> >   I've been able to do all of these steps for the file
> [2]ListFileReduced,
> >   as shown in the code (although it's clunky).
> >
> >   But, I would like to be able to do it for the other text file:
> [3]ListFile
> >   which has more articles. I used BeautifulSoup to scrape the data from
> the
> >   website, and then generated a list that I saved as a text file.
> >
> >   Best,
> >   Monzur
> >   On Wed, Mar 10, 2021 at 4:00 AM Dan Ciprus (dciprus)
> >   <[4]dcip...@cisco.com> wrote:
> >
> > If you could utilized pastebin or similar site to show your code, it
> > would help
> > tremendously since it's an unindented mess now and can not be read
> > easily.
> >
> > On Wed, Mar 10, 2021 at 03:07:14AM +0600, S Monzur wrote:
> > >Dear List,
> > >
> > >Newbie here. I am trying to loop over a text file to remove html
> tags,
> > >punctuation marks, stopwords. I have already used Beautiful Soup
> > (Python v
> > >3.8.3) to scrape the text (newspaper articles) from the site. It
> > returns a
> > >list that I saved as a file. However, I am not sure how to use a
> loop
> > in
> > >order to process all the items in the text file.
> > >
> > >In the code below I have used listfilereduced.text(containing data
> from
> > one
> > >news article, link to listfilereduced.txt here
> > ><[5]
> https://drive.google.com/file/d/1ojwN4u8cmh_nUoMJpdZ5ObaGW5URYYj3/view?usp=sharing
> >),
> > >however I would like to run this code on listfile.text(containing
> data
> > from
> > >multiple articles, link to listfile.text
> > ><[6]
> https://drive.google.com/file/d/1V3s8w8a3NQvex91EdOhdC9rQtCAOElpm/view?usp=sharing
> >
> > >).
> > >
> > >
> > >Any help would be greatly appreciated!
> > >
> > >P.S. The text is in a Non-English script, but the tags are all in
> > English.
> > >
> > >
> > >#The code below is for a textfile containing just one item. I am not
> > sure
> > >how to tweak this to make it run for listfile.text (which contains
> raw
> > data
> > >from multiple articles) with open('listfilereduced.txt', 'r',
> > >encoding='utf8') as my_file: rawData = my_file.read() print(rawData)
> > >#Separating body text from other data articleStart =
> rawData.find(" > >class=\"story-element story-element-text\">") articleData =
> > >rawData[:articleStart] articleBody = rawData[articleStart:]
> > >print(articleData) print("***") print(articleBody)
> print("***")
> > >#First, I define a function to strip tags from the body text def
> > >stripTags(pageContents): insideTag = 0 text = '' for char in
> > pageContents:
> > >if char

Re: How to loop over a text file (to remove tags and normalize) using Python

2021-03-10 Thread S Monzur
I initially scraped the links using beautiful soup, and from those links
downloaded the specific content of the articles I was interested in
(titles, dates, names of contributor, main texts) and stored that
information in a list. I then saved the list to a text file.
https://pastebin.com/8BMi9qjW . I am now trying to remove the html tags
from this text file, and running into issues as mentioned in the previous
post.



On Wed, Mar 10, 2021 at 3:46 PM Peter Otten <__pete...@web.de> wrote:

> On 10/03/2021 04:35, S Monzur wrote:
> > Thanks! I ended up using beautiful soup to remove the html tags and
> create
> > three lists (titles of article, publications dates, main body) but am
> still
> > facing a problem where the list is not properly storing the main body.
> > There is something wrong with my code for that section, and any comment
> > would be really helpful!
> >
> >   ListFile Text
> > <
> https://drive.google.com/file/d/1V3s8w8a3NQvex91EdOhdC9rQtCAOElpm/view?usp=sharing
> >
>
> How did you create that file?
>
>  > BeautifulSoup code for removing tags <https://pastebin.com/qvbVMUGD>
>
> > print(bodytext[0]) # so here, I'm only getting the first paragraph of
> the body of the first article, not all of the first article
> >
> > print(bodytext[1]) # here, I'm getting the second paragraph of the first
> article, and not the second article
>
> It may help if you process the individual articles with beautiful soup,
> not the whole list at once.
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: C Python extension to export an Function

2016-09-01 Thread Pavel S
If you're familiar with C++, I recommend to have a look at Boost::Python. 

Sample program:

#include 

#include 

void world()
{
std::cout << "hello world" << std::endl;
}


BOOST_PYTHON_MODULE( hello )
{
using namespace ::boost::python;

def( "world", &world );
}

Usage:

python -c "import hello; hello.world()"

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


Re: comapring 2 sequences of DNA ouput the silent and non mutations

2016-10-30 Thread Maxime S
2016-10-29 21:38 GMT+02:00 :
>
> Code:
>
> [...]
>
> for i in range (len(protein) & len(seq1)) :
>
> if protein[i] != mutantPRO[i] :
>print (protein[i] + str(i) + mutantPRO[i])
>A+= 1
> else:
> if seq1[i:i+3] != mutant[i:i+3]:
>  print(protein[i] + str(i) + mutantPRO[i] +'
Silent mutation ')
>  print(seq1[i:i+3] + mutant[i:i+3])
>  B+= 1

Hi,

The problem here is that you try to mix two different index in one
variable. Instead, you need to do something like this:

#i index protein
#j index DNA
for i in range (len(protein)) :
j = i*3
if protein[i] != mutantPRO[i] :
   print (protein[i] + str(i) + mutantPRO[i])
   A+= 1
else:
if seq1[j:j+3] != mutant[j:j+3]:
 print(protein[i] + str(i) + mutantPRO[i] +' Silent mutation ')
 print(seq1[j:j+3] + mutant[j:j+3])
 B+=1
-- 
https://mail.python.org/mailman/listinfo/python-list


Problem while building Python 3.6 from source.

2017-01-13 Thread Michael S
Hello,
I am new to this mailing-list and I really don't know whether this
mail should belong to python-dev. Please tell me, if so.


Unfortunately, I have got the following problem: I wanted to build and
install Python 3.6 from source but did not succeed.
To clarify my situation, I got as an operating system Debian jessie
8.6 and I used the xz compressed source tarball from
https://www.python.org/downloads/release/python-360/.
Concerning the build dependencies: I just executed:
$ sudo apt-get build-dep python3.4 (since 3.6 and 3.5 did not work).
Then I executed ./configure --enable-optimizations and make -j4 (I got 4 cores).
The output of make ended like:
'make: *** [profile-opt] Error 2'.
I had redirected the output and error of the configure and make commands via
$ make -j4 &> /home/username/make_output.txt.
Nevertheless I got an error to the console:
'*** Error in ./python'" free(): invalid next size (normal):
0x015bdf90 ***'.
Due to these error messages (this one and the one at the end of make)
I think the build was not successful.

How to solve this problem?

Of course I could send you the output and error files.

I'd be glad at any help.
-MichaelS
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Problem while building Python 3.6 from source.

2017-01-15 Thread Michael S
Thanks Thomas and ChrisA!

@Thomas: I don't know.. Unfortunately I am not as skilled as to be
able to find out..

@ChrisA: I tried your advice and think it worked. So, I just used $
./configure and then $ make. Then I was not sure, whether it had
worked so I used $ make test and got a fairly long result. At the end
there was a line like "test successful". Nevertheless not all of the
tests were successful.

So, now I got some questions:

1) Why did not all of the tests in $ make test succeed? But the end
line was "test successful". That confuses me.

2) This is more general. In order to get the build-dependencies I used
# apt-get build-dep python3.4. I also googled for the build
dependencies but did not find anything. So, how could I actually
figure out the build dependencies for Python3.6?


On Fri, Jan 13, 2017 at 7:19 PM, Chris Angelico  wrote:
> On Sat, Jan 14, 2017 at 5:00 AM, Michael S  wrote:
>> Hello,
>> I am new to this mailing-list and I really don't know whether this
>> mail should belong to python-dev. Please tell me, if so.
>
> Hi and welcome! This kind of thing is best on this list initially.
>
>> Unfortunately, I have got the following problem: I wanted to build and
>> install Python 3.6 from source but did not succeed.
>> To clarify my situation, I got as an operating system Debian jessie
>> 8.6 and I used the xz compressed source tarball from
>> https://www.python.org/downloads/release/python-360/.
>> Concerning the build dependencies: I just executed:
>> $ sudo apt-get build-dep python3.4 (since 3.6 and 3.5 did not work).
>
> That should be fine; the build dependencies of Python don't tend to
> change frequently. Jessie shipped with Python 3.4 but nothing newer,
> so there won't be packages for python3.5 or python3.6.
>
>> Then I executed ./configure --enable-optimizations and make -j4 (I got 4 
>> cores).
>> The output of make ended like:
>> 'make: *** [profile-opt] Error 2'.
>
> That just means that something went wrong. You'd have to scroll up to
> find the actual cause of the error.
>
>> I had redirected the output and error of the configure and make commands via
>> $ make -j4 &> /home/username/make_output.txt.
>> Nevertheless I got an error to the console:
>> '*** Error in ./python'" free(): invalid next size (normal):
>> 0x015bdf90 ***'.
>> Due to these error messages (this one and the one at the end of make)
>> I think the build was not successful.
>>
>> How to solve this problem?
>>
>> Of course I could send you the output and error files.
>
> The first thing I'd do would be to try a non-optimized build. Set your
> current build tree aside and re-extract into a new directory (that
> way, when you go back to playing with optimized builds, you don't have
> to redo the work), and run configure with no arguments. I'd also be
> inclined to run make with no arguments; there've been issues with
> parallel builds in enough projects that I've gotten into the habit of
> "problem? do it the slow way". If that build also fails, scroll up a
> bit and find where stuff failed.
>
> Are you familiar with building programs from source? If not, the best
> solution might be to post the entire log, but ideally, you should be
> able to skim through the last part of the log and report the actual
> problem that's cropping up.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Fwd: QUERY

2018-06-02 Thread S Srihari
To: python-list@python.org


I AM UNABLE TO INSTALL PYTHON.
KINDLY HELP ME.
-- 
https://mail.python.org/mailman/listinfo/python-list


can't install/run pip (Latest version of Python)

2018-07-15 Thread S Lea
 I can't seem to install the pips, DOS gives me the syntex i invalid, any
thoughts?

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


can't install/run pip (Latest version of Python)

2018-07-15 Thread S Lea
 I can't seem to install the pips, DOS gives me the syntex i invalid, any
thoughts?

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


Re: can't install/run pip (Latest version of Python)

2018-07-16 Thread S Lea
Thank you for reaching out.

1) Don't know what do you mean by the traceback.
2) In DOS, pip install pandas
3) Yes, in DOS, Win 10
4) 3.7
5) Not getting much info

On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp  wrote:

> On Sun, Jul 15, 2018 at 7:34 PM S Lea  wrote:
> >
> >  I can't seem to install the pips, DOS gives me the syntex i invalid, any
> > thoughts?
>
> You provide insufficient information for anyone to be able to help you.
>
> 1) Copy and paste the entire traceback into a plain text email, no
> screen shots please.
> 2) Copy and paste exactly what you typed that generated the syntax error.
> 3) Did you do all of this in cmd.exe in what version of Windows?  Or
> did you use something else?  Hopefully not in the interactive Python
> interpreter or IDLE!
> 4) What Python version are you using?
> 5) Did you try searching for the exact error message and see what
> answers might already be out there?
>
> If you provide these things, or, better, search and find the answer
> yourself, I'm sure someone will be happy to assist.
>
> Good luck!
> --
> boB
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: can't install/run pip (Latest version of Python)

2018-07-16 Thread S Lea
'pip' not recognized as internal or external command, operable program or
batch.

And for some reason it's a 32 bit version

On Mon, Jul 16, 2018 at 8:03 PM, S Lea  wrote:

> Thank you for reaching out.
>
> 1) Don't know what do you mean by the traceback.
> 2) In DOS, pip install pandas
> 3) Yes, in DOS, Win 10
> 4) 3.7
> 5) Not getting much info
>
> On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp  wrote:
>
>> On Sun, Jul 15, 2018 at 7:34 PM S Lea  wrote:
>> >
>> >  I can't seem to install the pips, DOS gives me the syntex i invalid,
>> any
>> > thoughts?
>>
>> You provide insufficient information for anyone to be able to help you.
>>
>> 1) Copy and paste the entire traceback into a plain text email, no
>> screen shots please.
>> 2) Copy and paste exactly what you typed that generated the syntax error.
>> 3) Did you do all of this in cmd.exe in what version of Windows?  Or
>> did you use something else?  Hopefully not in the interactive Python
>> interpreter or IDLE!
>> 4) What Python version are you using?
>> 5) Did you try searching for the exact error message and see what
>> answers might already be out there?
>>
>> If you provide these things, or, better, search and find the answer
>> yourself, I'm sure someone will be happy to assist.
>>
>> Good luck!
>> --
>> boB
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: can't install/run pip (Latest version of Python)

2018-07-16 Thread S Lea
Also, I can't find the location of Python insallation, it refers
to C:\Users\Precision\PycharmProjects\my first project from
video\venv\Scripts

On Mon, Jul 16, 2018 at 8:06 PM, S Lea  wrote:

> of python 3.7
>
> On Mon, Jul 16, 2018 at 8:06 PM, S Lea  wrote:
>
>> 'pip' not recognized as internal or external command, operable program or
>> batch.
>>
>> And for some reason it's a 32 bit version
>>
>> On Mon, Jul 16, 2018 at 8:03 PM, S Lea  wrote:
>>
>>> Thank you for reaching out.
>>>
>>> 1) Don't know what do you mean by the traceback.
>>> 2) In DOS, pip install pandas
>>> 3) Yes, in DOS, Win 10
>>> 4) 3.7
>>> 5) Not getting much info
>>>
>>> On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp 
>>> wrote:
>>>
>>>> On Sun, Jul 15, 2018 at 7:34 PM S Lea  wrote:
>>>> >
>>>> >  I can't seem to install the pips, DOS gives me the syntex i invalid,
>>>> any
>>>> > thoughts?
>>>>
>>>> You provide insufficient information for anyone to be able to help you.
>>>>
>>>> 1) Copy and paste the entire traceback into a plain text email, no
>>>> screen shots please.
>>>> 2) Copy and paste exactly what you typed that generated the syntax
>>>> error.
>>>> 3) Did you do all of this in cmd.exe in what version of Windows?  Or
>>>> did you use something else?  Hopefully not in the interactive Python
>>>> interpreter or IDLE!
>>>> 4) What Python version are you using?
>>>> 5) Did you try searching for the exact error message and see what
>>>> answers might already be out there?
>>>>
>>>> If you provide these things, or, better, search and find the answer
>>>> yourself, I'm sure someone will be happy to assist.
>>>>
>>>> Good luck!
>>>> --
>>>> boB
>>>> --
>>>> https://mail.python.org/mailman/listinfo/python-list
>>>>
>>>
>>>
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: can't install/run pip (Latest version of Python)

2018-07-16 Thread S Lea
of python 3.7

On Mon, Jul 16, 2018 at 8:06 PM, S Lea  wrote:

> 'pip' not recognized as internal or external command, operable program or
> batch.
>
> And for some reason it's a 32 bit version
>
> On Mon, Jul 16, 2018 at 8:03 PM, S Lea  wrote:
>
>> Thank you for reaching out.
>>
>> 1) Don't know what do you mean by the traceback.
>> 2) In DOS, pip install pandas
>> 3) Yes, in DOS, Win 10
>> 4) 3.7
>> 5) Not getting much info
>>
>> On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp 
>> wrote:
>>
>>> On Sun, Jul 15, 2018 at 7:34 PM S Lea  wrote:
>>> >
>>> >  I can't seem to install the pips, DOS gives me the syntex i invalid,
>>> any
>>> > thoughts?
>>>
>>> You provide insufficient information for anyone to be able to help you.
>>>
>>> 1) Copy and paste the entire traceback into a plain text email, no
>>> screen shots please.
>>> 2) Copy and paste exactly what you typed that generated the syntax error.
>>> 3) Did you do all of this in cmd.exe in what version of Windows?  Or
>>> did you use something else?  Hopefully not in the interactive Python
>>> interpreter or IDLE!
>>> 4) What Python version are you using?
>>> 5) Did you try searching for the exact error message and see what
>>> answers might already be out there?
>>>
>>> If you provide these things, or, better, search and find the answer
>>> yourself, I'm sure someone will be happy to assist.
>>>
>>> Good luck!
>>> --
>>> boB
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>>>
>>
>>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: can't install/run pip (Latest version of Python)

2018-07-17 Thread S Lea
 nd that leads to a
question, where did you get it?, and how long ago?  Maybe its an old
version?  Head scratcher for sure.

I have 3.7, downloaded a week ago
https://www.python.org/downloads/

Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Is this what you were suggesting?

On Mon, Jul 16, 2018 at 8:47 PM, Gene Heskett  wrote:

> On Monday 16 July 2018 23:06:19 S Lea wrote:
>
> > 'pip' not recognized as internal or external command, operable program
> > or batch.
> >
> > And for some reason it's a 32 bit version
> >
> Huh? My ancient wet ram memory is probably out to lunch, but ISTR reading
> about someone else with the same problem at least a year ago on this
> list, unfortunately I have a 90 day expiry setup on this list so
> searching is just an exercise. My email corpus is nearly 20 gigabytes
> now.
>
> pip has been around since it seems forever, but I would have thought by
> now it would have been rebuilt for 64 bit systems.  And that leads to a
> question, where did you get it?, and how long ago?  Maybe its an old
> version?  Head scratcher for sure.
>
> > On Mon, Jul 16, 2018 at 8:03 PM, S Lea  wrote:
> > > Thank you for reaching out.
> > >
> > > 1) Don't know what do you mean by the traceback.
>
> What you see in the terminal screen you ran it in. It should a press the
> left mouse button and wipe the mouse from beginning to end so its all
> highlighted, then position the curser in an email and press the middle
> mouse button, which should copy the highlighted text into the email.
>
> > > 2) In DOS, pip install pandas
> > > 3) Yes, in DOS, Win 10
> > > 4) 3.7
> > > 5) Not getting much info
> > >
> > > On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp 
> wrote:
> > >> On Sun, Jul 15, 2018 at 7:34 PM S Lea  wrote:
> > >> >  I can't seem to install the pips, DOS gives me the syntex i
> > >> > invalid,
> > >>
> > >> any
> > >>
> > >> > thoughts?
> > >>
> > >> You provide insufficient information for anyone to be able to help
> > >> you.
> > >>
> > >> 1) Copy and paste the entire traceback into a plain text email, no
> > >> screen shots please.
> > >> 2) Copy and paste exactly what you typed that generated the syntax
> > >> error. 3) Did you do all of this in cmd.exe in what version of
> > >> Windows?  Or did you use something else?  Hopefully not in the
> > >> interactive Python interpreter or IDLE!
> > >> 4) What Python version are you using?
> > >> 5) Did you try searching for the exact error message and see what
> > >> answers might already be out there?
> > >>
> > >> If you provide these things, or, better, search and find the answer
> > >> yourself, I'm sure someone will be happy to assist.
> > >>
> > >> Good luck!
> > >> --
> > >> boB
> > >> --
> > >> https://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> Cheers, Gene Heskett
> --
> "There are four boxes to be used in defense of liberty:
>  soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> Genes Web page <http://geneslinuxbox.net:6309/gene>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: can't install/run pip (Latest version of Python)

2018-07-17 Thread S Lea
Terry,

BLESS YOU!!!

The second option worked I installed python 3.7 and
then pycharm-community-2018.1.4. I'm following a video course by TTC How To
Program: Computer Science Concepts And Python Exercises. The instructor
suggested to install pycharm community. I'm also following a few youtube
videos on data analyses. Like  sentdex, https://www.youtube.com/user/sentdex,
but he is pretty advanced, even his basic tutorials. I didn't touch
programming from HS about 20yrs ago.  Is python a good way to start and
learn or use anaconda?  This guy from sendex uses IDLE, but after I
installed pycharms, I can't bring it up and the background is black, but I
started w/ white.
 Would you suggest resources to learn from? I'm in finance and it seems
python is way ahead of excel.

Thank you,
Stan

C:\Users\Precision>py -3.7 -m pip install pandas
Collecting pandas
  Downloading https://files.pythonhosted.org/packages/a9/e8/
ca7637c51767809cd7328dd01e246b8f2ec0fde566c9b7440b91d9a33460
/pandas-0.23.3-cp37-cp37m-win32.whl (6.8MB)
100% |████| 6.8MB 620kB/s
Collecting pytz>=2011k (from pandas)
  Downloading https://files.pythonhosted.org/packages/30/4e/
27c34b62430286c6d59177a0842ed90dc789ce5d1ed740887653b898779a
/pytz-2018.5-py2.py3-none-any.whl (510kB)
100% |████| 512kB 810kB/s
Collecting python-dateutil>=2.5.0 (from pandas)
  Downloading https://files.pythonhosted.org/packages/cf/f5/
af2b09c957ace60dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825
/python_dateutil-2.7.3-py2.py3-none-any.whl (211kB)
100% |████| 215kB 646kB/s
Collecting numpy>=1.9.0 (from pandas)
  Downloading https://files.pythonhosted.org/packages/6c/28/
010d2433a02bdb7a2d20638953cdb8c6b0324b9c5c431e444a5c5ad40dd7
/numpy-1.14.5-cp37-none-win32.whl (9.8MB)
100% |████| 9.8MB 661kB/s
Collecting six>=1.5 (from python-dateutil>=2.5.0->pandas)
  Downloading https://files.pythonhosted.org/packages/67/4b/
141a581104b1f6397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a
/six-1.11.0-py2.py3-none-any.whl
Installing collected packages: pytz, six, python-dateutil, numpy, pandas

On Tue, Jul 17, 2018 at 12:09 AM, Terry Reedy  wrote:

> On 7/16/2018 11:03 PM, S Lea wrote:
>
> Some additional info, which allows me to say the following:
>
> 1) Don't know what do you mean by the traceback.
>>
>
> >>> 1/o
> Traceback (most recent call last):
>   File "", line 1, in 
> 1/o
> NameError: name 'o' is not defined
>
> The last four lines
>
> 2) In DOS, pip install pandas
>>
>
> Try the core-developer recommended way to run modules:
> python -m pip install pandas
> or, if you installed the py launcher and have multiple python versions
> py -3.7 -m pip install pandas
>
> If you see something about pip not being installed,
> python -m ensurepip
>
> 3) Yes, in DOS, Win 10
>>
>
> Crucial info.
>
> 4) 3.7
>>
>
> Allowed me to specify how to specifically launch 3.7.
>
>
> 5) Not getting much info
>>
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: can't install/run pip (Latest version of Python)

2018-07-17 Thread S Lea
Also, how does one get a 64 bit version?

On Tue, Jul 17, 2018 at 4:04 PM, S Lea  wrote:

> Terry,
>
> BLESS YOU!!!
>
> The second option worked I installed python 3.7 and
> then pycharm-community-2018.1.4. I'm following a video course by TTC How
> To Program: Computer Science Concepts And Python Exercises. The instructor
> suggested to install pycharm community. I'm also following a few youtube
> videos on data analyses. Like  sentdex, https://www.youtube.
> com/user/sentdex, but he is pretty advanced, even his basic tutorials. I
> didn't touch programming from HS about 20yrs ago.  Is python a good way to
> start and learn or use anaconda?  This guy from sendex uses IDLE, but after
> I installed pycharms, I can't bring it up and the background is black, but
> I started w/ white.
>  Would you suggest resources to learn from? I'm in finance and it seems
> python is way ahead of excel.
>
> Thank you,
> Stan
>
> C:\Users\Precision>py -3.7 -m pip install pandas
> Collecting pandas
>   Downloading https://files.pythonhosted.org/packages/a9/e8/ca7637c5176780
> 9cd7328dd01e246b8f2ec0fde566c9b7440b91d9a33460/pandas-0.23.
> 3-cp37-cp37m-win32.whl (6.8MB)
> 100% || 6.8MB 620kB/s
> Collecting pytz>=2011k (from pandas)
>   Downloading https://files.pythonhosted.org/packages/30/4e/27c34b62430286
> c6d59177a0842ed90dc789ce5d1ed740887653b898779a/pytz-2018.5-
> py2.py3-none-any.whl (510kB)
> 100% || 512kB 810kB/s
> Collecting python-dateutil>=2.5.0 (from pandas)
>   Downloading https://files.pythonhosted.org/packages/cf/f5/af2b09c957ace6
> 0dcfac112b669c45c8c97e32f94aa8b56da4c6d1682825/python_
> dateutil-2.7.3-py2.py3-none-any.whl (211kB)
> 100% || 215kB 646kB/s
> Collecting numpy>=1.9.0 (from pandas)
>   Downloading https://files.pythonhosted.org/packages/6c/28/010d2433a02bdb
> 7a2d20638953cdb8c6b0324b9c5c431e444a5c5ad40dd7/numpy-1.14.5-
> cp37-none-win32.whl (9.8MB)
> 100% || 9.8MB 661kB/s
> Collecting six>=1.5 (from python-dateutil>=2.5.0->pandas)
>   Downloading https://files.pythonhosted.org/packages/67/4b/141a581104b1f6
> 397bfa78ac9d43d8ad29a7ca43ea90a2d863fe3056e86a/six-1.11.0-
> py2.py3-none-any.whl
> Installing collected packages: pytz, six, python-dateutil, numpy, pandas
>
> On Tue, Jul 17, 2018 at 12:09 AM, Terry Reedy  wrote:
>
>> On 7/16/2018 11:03 PM, S Lea wrote:
>>
>> Some additional info, which allows me to say the following:
>>
>> 1) Don't know what do you mean by the traceback.
>>>
>>
>> >>> 1/o
>> Traceback (most recent call last):
>>   File "", line 1, in 
>> 1/o
>> NameError: name 'o' is not defined
>>
>> The last four lines
>>
>> 2) In DOS, pip install pandas
>>>
>>
>> Try the core-developer recommended way to run modules:
>> python -m pip install pandas
>> or, if you installed the py launcher and have multiple python versions
>> py -3.7 -m pip install pandas
>>
>> If you see something about pip not being installed,
>> python -m ensurepip
>>
>> 3) Yes, in DOS, Win 10
>>>
>>
>> Crucial info.
>>
>> 4) 3.7
>>>
>>
>> Allowed me to specify how to specifically launch 3.7.
>>
>>
>> 5) Not getting much info
>>>
>>
>> --
>> Terry Jan Reedy
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: can't install/run pip (Latest version of Python)

2018-07-17 Thread S Lea
What do you use, Gene?
It seems most business program run on Windows.

On Tue, Jul 17, 2018 at 5:14 PM, Gene Heskett  wrote:

> On Tuesday 17 July 2018 18:48:22 S Lea wrote:
>
> >  nd that leads to a
> > question, where did you get it?, and how long ago?  Maybe its an old
> > version?  Head scratcher for sure.
> >
> > I have 3.7, downloaded a week ago
> > https://www.python.org/downloads/
> >
> > Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32
> > bit (Intel)] on win32
> > Type "help", "copyright", "credits" or "license" for more information.
> >
> > Is this what you were suggesting?
>
> I wasn't clear enough, I was referring to your 'pip' install. But since
> this idents the 3.7 as 32 bit, I wonder if there is a 64 bit version
> there too. Yes, there are 3 of each, and I suspect you need the x86-64
> versions.
>
> Or I could be full of it, the last windows install I allowed here was XP,
> and when I found its drivers couldn't run the radio in an HP lappy I had
> bought for a road machine, the drive got formatted and mandrake
> installed, which at least tried to run the radio. So other than
> configuring friends networking on more recent windows installs, I have
> essentially zero windows expertise. Windows is a disease I try very hard
> to stay away from.
>
> So I'll bow out and let someone more knowledgable step in.
>
> >
> > On Mon, Jul 16, 2018 at 8:47 PM, Gene Heskett 
> wrote:
> > > On Monday 16 July 2018 23:06:19 S Lea wrote:
> > > > 'pip' not recognized as internal or external command, operable
> > > > program or batch.
> > > >
> > > > And for some reason it's a 32 bit version
> > >
> > > Huh? My ancient wet ram memory is probably out to lunch, but ISTR
> > > reading about someone else with the same problem at least a year ago
> > > on this list, unfortunately I have a 90 day expiry setup on this
> > > list so searching is just an exercise. My email corpus is nearly 20
> > > gigabytes now.
> > >
> > > pip has been around since it seems forever, but I would have thought
> > > by now it would have been rebuilt for 64 bit systems.  And that
> > > leads to a question, where did you get it?, and how long ago?  Maybe
> > > its an old version?  Head scratcher for sure.
> > >
> > > > On Mon, Jul 16, 2018 at 8:03 PM, S Lea  wrote:
> > > > > Thank you for reaching out.
> > > > >
> > > > > 1) Don't know what do you mean by the traceback.
> > >
> > > What you see in the terminal screen you ran it in. It should a press
> > > the left mouse button and wipe the mouse from beginning to end so
> > > its all highlighted, then position the curser in an email and press
> > > the middle mouse button, which should copy the highlighted text into
> > > the email.
> > >
> > > > > 2) In DOS, pip install pandas
> > > > > 3) Yes, in DOS, Win 10
> > > > > 4) 3.7
> > > > > 5) Not getting much info
> > > > >
> > > > > On Sun, Jul 15, 2018 at 5:44 PM, boB Stepp
> > > > > 
> > >
> > > wrote:
> > > > >> On Sun, Jul 15, 2018 at 7:34 PM S Lea  wrote:
> > > > >> >  I can't seem to install the pips, DOS gives me the syntex i
> > > > >> > invalid,
> > > > >>
> > > > >> any
> > > > >>
> > > > >> > thoughts?
> > > > >>
> > > > >> You provide insufficient information for anyone to be able to
> > > > >> help you.
> > > > >>
> > > > >> 1) Copy and paste the entire traceback into a plain text email,
> > > > >> no screen shots please.
> > > > >> 2) Copy and paste exactly what you typed that generated the
> > > > >> syntax error. 3) Did you do all of this in cmd.exe in what
> > > > >> version of Windows?  Or did you use something else?  Hopefully
> > > > >> not in the interactive Python interpreter or IDLE!
> > > > >> 4) What Python version are you using?
> > > > >> 5) Did you try searching for the exact error message and see
> > > > >> what answers might already be out there?
> > > > >>
> > > > >> If you provide these things, or, better, search and find the
> > > > >> answer yourself, I'm sure someone will be happy to assist.
> > > > >>
> > > > >> Good luck!
> > > > >> --
> > > > >> boB
> > > > >> --
> > > > >> https://mail.python.org/mailman/listinfo/python-list
> > >
> > > --
> > > Cheers, Gene Heskett
> > > --
> > > "There are four boxes to be used in defense of liberty:
> > >  soap, ballot, jury, and ammo. Please use in that order."
> > > -Ed Howdershelt (Author)
> > > Genes Web page <http://geneslinuxbox.net:6309/gene>
> > > --
> > > https://mail.python.org/mailman/listinfo/python-list
>
>
>
> --
> Cheers, Gene Heskett
> --
> "There are four boxes to be used in defense of liberty:
>  soap, ballot, jury, and ammo. Please use in that order."
> -Ed Howdershelt (Author)
> Genes Web page <http://geneslinuxbox.net:6309/gene>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Setting Return-Path in email

2016-05-23 Thread ragav s
Hi all,

How can i add different Return-path and fromid in python.i have pasted the 
below code for preview


def sendMail(sub,fromid,to,cc,html):
msg = MIMEMultipart('alternative')
msg['Subject'] = sub
msg['From'] = fromid
msg['To'] = to
toaddress = [to]
if cc:
msg['Cc'] = cc
toaddress = to+","+ cc
toaddress = toaddress.split(",")

type = 'plain'
part = MIMEText(html, type,'utf-8')
msg.attach(part)

s = smtplib.SMTP('localhost')
s.sendmail(fromid,toaddress, msg.as_string())
s.quit()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: errorhandler 2.0.0 Released!

2016-06-06 Thread Pavel S
Hi,
can you explain, why is the attribute 'fired' class-level and not 
instance-level? There must be good reason for modifying class attribute from 
instance.


Dne pondělí 6. června 2016 15:26:08 UTC+2 Chris Withers napsal(a):
> Hi All,
> 
> errorhandler is a tiny but useful logging handler for the python logging 
> framework. It lets you tell when logging above a certain level has 
> occurred, even if it's not in code you can control.
> 
> I'm pleased to announce the release of errorhandler 2.0.0 featuring the 
> following:
> 
> - Support for Python 3
> 
> - Documentation on Read The Docs
> 
> - Continuous testing using Travis CI
> 
> - Code coverage reporting through Coveralls
> 
> The package is on PyPI and a full list of all the links to docs, issue 
> trackers and the like can be found here:
> 
> https://github.com/Simplistix/errorhandler
> 
> Any questions, please do ask on the Testing in Python list or on the 
> Simplistix open source mailing list...
> 
> cheers,
> 
> Chris
> 
> -- 
> Simplistix - Content Management, Batch Processing & Python Consulting
>  - http://www.simplistix.co.uk

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


Re: UserList - which methods needs to be overriden?

2016-06-10 Thread Maxime S
2016-06-10 10:37 GMT+02:00 Peter Otten <__pete...@web.de>:
>
> Nagy László Zsolt wrote:
>
> > I'm not sure wich one is the best. Peter wrote that UserList was left in
> > collections only for backward compatiblity. This might be a point
>
> I'll take that back. I looked around and found no evidence for my claim.
> Only MutableString was removed during the transition to Python 3.
>
> Sorry for the confusion.
>
>

Up to Python 2.6, the docs of UserList had a note stating that:

This module is available for backward compatibility only. If you are
writing code that does not need to work with versions of Python earlier
than Python 2.2, please consider subclassing directly from the built-in
list type.

This was changed in Python 2.7 to:

When Python 2.2 was released, many of the use cases for this class were
subsumed by the ability to subclass list directly. However, a handful of
use cases remain.

So I think the intention was that the ability to subclass list would remove
the need to subclass UserList, but it was later realised that it is not
totally the case.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: mod_python compilation error in VS 2008 for py2.7.1

2016-06-14 Thread Pavel S
Have you considered to use rather WSGI-based solution? (for Apache Httpd is 
mod_wsgi). Mod_python is totally obsolete.
-- 
https://mail.python.org/mailman/listinfo/python-list


__all__ attribute: bug and proposal

2016-06-27 Thread Pavel S
Hi,
I today uncovered subtle bug and would like to share it with you.

By a mistake, I forgot to put comma into '__all__' tuple of some module. Notice 
missing comma after 'B'.

# module foo.py
__all__ = (
'A',
'B'
'C',
)

class A: pass
class B: pass
class C: pass

If you try to import * from the module, it will raise an error, because 'B' and 
'C' will be concatenated into 'BC'.

>>> from foo import *
AttributeError: 'module' object has no attribute 'BC'

The bug won't be found until someone imports *.
In order to identify problems as soon as possible, here's the proposal.

Porposal: allow putting objects into __all__ directly, so possible problems 
will be found earlier:

# module foo.py
class A: pass
class B: pass
class C: pass

__all__ = (A, B, C)

Note: this currently don't work.

>>> from foo import *
TypeError: attribute name must be string, not 'type'
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: __all__ attribute: bug and proposal

2016-06-27 Thread Pavel S
> but what about integers or strings?

Can you provide example?

---
No matter if __all__ uses names or objects, I think it should be validated not 
only when importing '*', but always.

Frankly, do you always unit-test if __all__ works?
-- 
https://mail.python.org/mailman/listinfo/python-list


How to only read words within brackets/ parentheses (in .txt file) using Python

2019-09-04 Thread A S
I understand that reading lines in .txt files would look something like this in 
Python:


with open('filename','r') as fd:
   lines = fd.readlines()


However, how do I run my code to only read the words in my .txt files that are 
within each balanced parenthesis?

I am not sure how to go about it, let's say my .txt file contents lines like 
this:

k;

select xx("xE'", PUT(xx..),"'") jdfjhf:jhfjj from _x_xx_L ;
quit; 

/* 1.x FROM _x_Ex_x */ 
proc sql; "TRUuuuth");
hhhjhfjs as fdsjfsj:
select * from djfkjd to jfkjs
(SELECT abc AS abc1, abc_2_ AS efg, abc_fg, fkdkfj_vv, jjsflkl_ff, fjkdsf_jfkj
FROM &xxx..xxx_xxx_xxE
   where (xxx(xx_ix as format '-xx') gff &jfjfsj_jfjfj.) and 
  (xxx(xx_ix as format '-xx') lec &jgjsd_vnv.)
);


The main idea is to read only these portions of the .txt file (i.e. Those 
within parentheses):

 ("xE'", PUT(xx..),"'") jdfjhf:jhfjj from _x_xx_L ;
quit; 

/* 1.x FROM _x_Ex_x */ 
proc sql; "TRUuuuth")

(SELECT abc AS abc1, abc_2_ AS efg, abc_fg, fkdkfj_vv, jjsflkl_ff, fjkdsf_jfkj
FROM &xxx..xxx_xxx_xxE
   where (xxx(xx_ix as format '-xx') gff &jfjfsj_jfjfj.) and 
  (xxx(xx_ix as format '-xx') lec &jgjsd_vnv.)
)



Any help will be truly appreciated
-- 
https://mail.python.org/mailman/listinfo/python-list


Finding lines in .txt file that contain keywords from two different set()

2019-09-08 Thread A S
My problem is seemingly profound but I hope to make it sound as simplified as 
possible.Let me unpack the details..:

1. I have one folder of Excel (.xlsx) files that serve as a data dictionary.

-In Cell A1, the data source name is written in between brackets

-In Cols C:D, it contains the data field names (It could be in either col C or 
D in my actual Excel sheet. So I had to search both columns

-*Important: I need to know which data source the field names come from

2. I have another folder of Text (.txt) files that I need to parse through to 
find these keywords.

These are the folders used for a better reference ( 
https://drive.google.com/open?id=1_LcceqcDhHnWW3Nrnwf5RkXPcnDfesq ). The files 
are found in the folder.

This is the code I have thus far...:

import os, sys
from os.path
import join
import re
import xlrd
from xlrd import open_workbook
import openpyxl
from openpyxl.reader.excel import load_workbook
import xlsxwriter


#All the paths
dict_folder = 'C:/Users//Documents//Test Excel' 
text_folder = 'C:/Users//Documents//Text'

words = set()
fieldset = set()
for file in os.listdir(dict_folder):
if file.endswith(".xlsx"):
wb1 = load_workbook(join(dict_folder, file), data_only = True)
ws = wb1.active
   #Here I am reading and printing all the data source names set(words) in the 
excel dictionaries:
cellvalues = ws["A1"].value
wordsextract = re.findall(r"\((.+?)\)", str(cellvalues))
results = wordsextract[0]
words.add(results)
print(results)

for rowofcellobj in ws["C" : "D"]:
for cellobj in rowofcellobj:
   #2. Here I am printing all the field names in col C & D in the excel 
dictionaries:
data = re.findall(r"\w+_.*?\w+", str(cellobj.value))
if data != []:
fields = data[0]
fieldset.add(fields)
print(fieldset)
#listing = str.remove("")
#print(listing)   


#Here I am reading the name of each .txt file to the separate .xlsx file:
for r, name in enumerate(os.listdir(text_folder)):
if name.endswith(".txt"):
print(name)

#Reading .txt file and trying to make the sentence into words instead of lines 
so that I can compare the individual .txt file words with the .xlsx file 
txtfilespath = os.chdir("C:/Users//Documents//Text")


#Here I am reading and printing all the words in the .txt files and compare 
with the excel Cell A1:
for name in os.listdir(txtfilespath):
if name.endswith(".txt"):
    with open (name, "r") as texts:
# Read each line of the file:
s = texts.read()
print(s)


#if .txt files contain.() or select or from or words from 
sets..search that sentence and extract the common fields

result1 = []
parens = 0
buff = ""
for line in s:
if line == "(":
parens += 1
if parens > 0:
buff += line
if line == ")":
parens -= 1
   if not parens and buff:
result1.append(buff)
buff = ""
set(result1)

#Here, I include other keywords other than those found in the Excel workbooks 
   checkhere = set()   
   checkhere.add("Select")
   checkhere.add("From")
   checkhere.add("select")
   checkhere.add("from")
   checkhere.add("SELECT")
   checkhere.add("FROM")
   # k = list(checkhere)
   # print(k)  

   #I only want to read/ extract the lines containing brackets () as well as 
the keywords in the checkhere set. So that I can check capture the source and 
field in each line:
   #I tried this but nothing was printed..
   for element in checkhere:
   if element in result1:
print(result1)


My desired output for the code that could not be printed when I tried is:

(/* 1.select_no., bi FROM apple_x_Ex_x */ 
 proc sql; "TRUuuuth")

(/* 1.x FROM x*/ 
proc sql; "TRUuuuth")

(SELECT abc AS abc1, ab33_2_ AS mon, a_rr, iirir_vf, jk_ff, sfa_jfkj
FROM &orange..xxx_xxx_xxE
 where (asre(kkk_ix as format '-xx') gff &bcbcb_hhaha.) and 
  (axx(xx_ix as format '-xx') lec &jgjsd_vnv.)
 )

 (/* 1.select_no. FROM apple_x_Ex_x */ 
 proc sql; "TRUuuuth")

 (SELECT abc AS kf, mcfg_2_ AS dokn, b_rr, jjhj_vf, jjjk_hj, fjjh_jhjkj
FROM &bfbd..pear_xxx_xxE
 where (afdfe(kkffk_ix as format 'd-xx') gdaff &bcdadabcb_hdahaha.) and 
  (axx(xx_ix as format '-xx') lec &jgjsdfdf_vnv.)
 )



After which, if I'm able to get the desired output above, I will then compare 
these lines against the word set() and the fieldset set().

Any help would really be appreciated here..thank you
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: psutil.boot_time() ... doesn't ?

2019-11-06 Thread Maxime S
Hello,

You may want to read PEP 418 which nicely summaries the different clock
available on each platform and their limitations.

It looks like CLOCK_BOOTTIME is what you want but it is only available on
Linux.

Regards,

Maxime.

Le mer. 6 nov. 2019 à 18:23, R.Wieser  a écrit :

> Hello all,
>
> I was doing a "lets print some time-related data", and also diaplayed the
> result of "psutil.boot_time()".
>
> Somewhere while doing that I saw that my clock was off, so I used the
> "date"
> command to rectify it.
>
> The thing is, after that the result of "psutil.boot_time()" was changed -
> and that I did (and do) not expect. :-(
> (Remark: the difference was exactly the same as the change I made with the
> "date" command).
>
> Question: Is there a way to retrieve the "last boot" time /without/ it
> getting changed by ... whatever ?
>
> Regards,
> Rudy Wieser
>
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Extract sentences in nested parentheses using Python

2019-12-02 Thread A S
I am trying to extract all strings in nested parentheses (along with the 
parentheses itself) in my .txt file. Please see the sample .txt file that I 
have used in this example here: 
(https://drive.google.com/open?id=1UKc0ZgY9Fsz5O1rSeBCLqt5dwZkMaQgr).

I have tried and done up three different codes but none of them seems to be 
able to extract all the nested parentheses. They can only extract a portion of 
the nested parentheses. Any advice on what I've done wrong could really help!

Here are the three codes I have done so far:

1st attempt:

import re
from os.path import join

def balanced_braces(args):
parts = []
for arg in args:
if '(' not in arg:
continue
chars = []
n = 0
for c in arg:
if c == '(':
if n > 0:
chars.append(c)
n += 1
elif c == ')':
n -= 1
if n > 0:
chars.append(c)
elif n == 0:
parts.append(''.join(chars).lstrip().rstrip())
chars = []
elif n > 0:
chars.append(c)
return parts

with open('lan sample text file.txt','r') as fd:
#for words in fd.readlines():   
t1 = balanced_braces(fd);
print(t1)


Output:

['"xE\'", PUT(xx..),"\'"', '"TRUuuuth"', "xxx(xx_ix as format '-xx') 
lec &jgjsd_vnv.", '"xE\'", PUT(xx..),"\'"', '"CUuuuth"', "xxx(xx_ix as 
format '-xx') lec &jgjsd_vnv."]



2nd attempt:

from pyparsing import nestedExpr

matchedParens = nestedExpr('(',')')
with open('lan sample text file.txt','r') as fd:
for words in fd.readlines():
for e in matchedParens.searchString(words):
print(e)


Output:

[['"xE\'"', ',', 'PUT', ['xx..'], ',', '"\'"']]
[['"TRUuuuth"']]
[['xxx', ['xx_ix', 'as', 'format', "'-xx'"], 'gff', '&jfjfsj_jfjfj.']]
[['xxx', ['xx_ix', 'as', 'format', "'-xx'"], 'lec', '&jgjsd_vnv.']]
[['"xE\'"', ',', 'PUT', ['xx..'], ',', '"\'"']]
[['"CUuuuth"']]
[['xxx', ['xx_ix', 'as', 'format', "'-xx'"], 'gff', '&jfjfsj_jfjfj.']]
[['xxx', ['xx_ix', 'as', 'format', "'-xx'"], 'lec', '&jgjsd_vnv.']]



3rd attempt:

def parse_segments(source, recurse=False):

unmatched_count = 0
start_pos = 0
opened = False
open_pos = 0
cur_pos = 0

finished = []
segments = []

for character in source:
#scan for mismatched parenthesis:
if character == '(':
unmatched_count += 1
if not opened:
open_pos = cur_pos
opened = True

if character == ')':
unmatched_count -= 1

if opened and unmatched_count == 0:
segment = source[open_pos:cur_pos+1]
segments.append(segment)
clean = source[start_pos:open_pos]
if clean:
finished.append(clean)
opened = False
start_pos = cur_pos+1

cur_pos += 1

   # assert unmatched_count == 0

if start_pos != cur_pos:
#get anything that was left over here
finished.append(source[start_pos:cur_pos])

#now check on recursion:
for item in segments:
#get rid of bounding parentheses:
pruned = item[1:-1]
if recurse:
results = parse_tags(pruned, recurse)
finished.expand(results)
else:
finished.append(pruned)

return finished

with open('lan sample text file.txt','r') as fd:
for words in fd.readlines():
t = parse_segments(words)
print(t)


Output:

['k;\n']
['\n']
['  select xx', ' jdfjhf:jhfjj from _x_xx_L ;\n', '"xE\'", 
PUT(xx..),"\'"']
['quit; \n']
['\n']
['/* 1.x FROM _x_Ex_x */ \n']
['proc sql; ', ';\n', '"TRUuuuth"']
['hhhjhfjs as fdsjfsj:\n']
['select * from djfkjd to jfkjs\n']
['(\n']
['SELECT abc AS abc1, abc_2_ AS efg, abc_fg, fkdkfj_vv, jjsflkl_ff, 
fjkdsf_jfkj\n']
['\tFROM &xxx..xxx_xxx_xxE\n']
["where ((xxx(xx_ix as format '-xx') gff &jfjfsj_jfjfj.) and \n"]
['  ', ')\n', "xxx(xx_ix as format '-xx') lec &jgjsd_vnv."]
[' );\n']
['\n']
['\n']
['jj;\n']
['\n']
['  select xx', ' jdfjhf:jhfjj from _x_xx_L ;\n', '"xE\'", 
PUT(xx..),"\'"']
['quit; \n']
['\n']
['/* 1.x FROM _x_Ex_x */ \n']
['proc sql; ', ';\n', '"CUuuuth"']
['hhhjhfjs as fdsjfsj:\n']
['select * from djfkjd to jfkjs\n']
['(SELECT abc AS abc1, abc_2_ AS efg, abc_fg, fkdkfj_vv, jjsflkl_ff, 
fjkdsf_jfkj\n']
['\tFROM &xxx..xxx_xxx_xxE\n']
["where ((xxx(xx_ix as format '-xx') gff &jfjfsj_jfjfj.) and \n"]
['  ', ')\n', "xxx(xx_ix as format '-xx') lec &jgjsd_vnv."]
[' );']




My intended Output that I am unable to get should look something like this:


("xE'", PUT(xx..),"'")
("TRUuuuth")
(
SELECT abc AS abc1, abc_2_ AS efg, abc_fg, fkdkfj_vv, jjsflkl_ff, fjkdsf_jfkj
FROM &xxx..xxx_xxx_xxE
where ((xxx(xx_ix as format '-xx') gff &jfjfsj_jfjfj.) and
  (xxx(xx_ix a

Re: Extract sentences in nested parentheses using Python

2019-12-03 Thread A S
On Tuesday, 3 December 2019 01:01:25 UTC+8, Peter Otten  wrote:
> A S wrote:
> 
> I think I've seen this question before ;)
> 
> > I am trying to extract all strings in nested parentheses (along with the
> > parentheses itself) in my .txt file. Please see the sample .txt file that
> > I have used in this example here:
> > (https://drive.google.com/open?id=1UKc0ZgY9Fsz5O1rSeBCLqt5dwZkMaQgr).
> > 
> > I have tried and done up three different codes but none of them seems to
> > be able to extract all the nested parentheses. They can only extract a
> > portion of the nested parentheses. Any advice on what I've done wrong
> > could really help!
> > 
> > Here are the three codes I have done so far:
> > 
> > 1st attempt:
> > 
> > import re
> > from os.path import join
> > 
> > def balanced_braces(args):
> > parts = []
> > for arg in args:
> > if '(' not in arg:
> > continue
> 
> There could still be a ")" that you miss
> 
> > chars = []
> > n = 0
> > for c in arg:
> > if c == '(':
> > if n > 0:
> > chars.append(c)
> > n += 1
> > elif c == ')':
> > n -= 1
> > if n > 0:
> > chars.append(c)
> > elif n == 0:
> > parts.append(''.join(chars).lstrip().rstrip())
> > chars = []
> > elif n > 0:
> > chars.append(c)
> > return parts
> 
> It's probably easier to understand and implement when you process the 
> complete text at once. Then arbitrary splits don't get in the way of your 
> quest for ( and ). You just have to remember the position of the first 
> opening ( and number of opening parens that have to be closed before you 
> take the complete expression:
> 
> level:  000100
> text:   abc(def(gh))ij
>when we are here^
> we need^
> 
> A tentative implementation:
> 
> $ cat parse.py
> import re
> 
> NOT_SET = object()
> 
> def scan(text):
> level = 0
> start = NOT_SET
> for m in re.compile("[()]").finditer(text):
> if m.group() == ")":
> level -= 1
> if level < 0:
> raise ValueError("underflow: more closing than opening 
> parens")
> if level == 0:
> # outermost closing parenthesis:
> # deliver enclosed string including parens.
> yield text[start:m.end()]
> start = NOT_SET
> elif m.group() == "(":
> if level == 0:
> # outermost opening parenthesis: remember position.
> assert start is NOT_SET
> start = m.start()
> level += 1
> else:
> assert False
> if level > 0:
> raise ValueError("unclosed parens remain")
> 
> 
> if __name__ == "__main__":
> with open("lan sample text file.txt") as instream:
> text = instream.read()
> for chunk in scan(text):
> print(chunk)
> $ python3 parse.py
> ("xE'", PUT(xx..),"'")
> ("TRUuuuth")

Hello Peter! I tried this on my actual working files and it returned this 
error: "unclosed parens remain". In this case, how can I continue to parse 
through my text files by only extracting those with balanced parentheses and 
ignore those that are incomplete?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract sentences in nested parentheses using Python

2019-12-05 Thread A S
On Tuesday, 3 December 2019 06:22:52 UTC+8, DL Neil  wrote:
> On 3/12/19 6:00 AM, Peter Otten wrote:
> > A S wrote:
> > I think I've seen this question before ;)
> 
> In addition to 'other reasons' for @Peter's comment, it is a common 
> ComSc worked-problem or assignment. (in which case, we'd appreciate 
> being told that you/OP is asking for help with "homework")
> 
> 
> >> I am trying to extract all strings in nested parentheses (along with the
> >> parentheses itself) in my .txt file. Please see the sample .txt file that
> >> I have used in this example here:
> >> (https://drive.google.com/open?id=1UKc0ZgY9Fsz5O1rSeBCLqt5dwZkMaQgr).
> >>
> >> I have tried and done up three different codes but none of them seems to
> >> be able to extract all the nested parentheses. They can only extract a
> >> portion of the nested parentheses. Any advice on what I've done wrong
> >> could really help!
> 
> One approach is to research in the hope that there are already existing 
> tools or techniques which may help/save you from 'reinventing the wheel' 
> - when you think about it, a re-statement of open-source objectives.
> 
> How does the Python interpreter break-down Python (text) code into its 
> constituent parts ("tokens") *including* parentheses? Such are made 
> available in (perhaps) a lesser-known corner of the PSL (Python Standard 
> Library). Might you be able to use one such tool?
> 
> The ComSc technique which sprang to mind involves "stacks" (a LIFO data 
> structure) and "RPN" (Reverse Polish Notation). Whereas we like people 
> to take their turn when it comes to limited resources, eg to form a 
> "queue" to purchase/pay for goods at the local store, which is "FIFO" 
> (first-in, first-out); a "stack"/LIFO (last-in, first-out) can be 
> problematic to put into practical application. There are plenty of 
> Python implementations or you can 'roll your own' with a list. Again, 
> I'd likely employ a "deque" from the PSL's Collections library (although 
> as a "stack" rather than as a "double-ended queue"), because the 
> optimisation comes "free". (to my laziness, but after some kind soul 
> sweated-bullets to make it fast (in both senses) for 'the rest of us'!)
> 
> 
> > It's probably easier to understand and implement when you process the
> > complete text at once. Then arbitrary splits don't get in the way of your
> > quest for ( and ). You just have to remember the position of the first
> > opening ( and number of opening parens that have to be closed before you
> > take the complete expression:
> 
> +1
> but as a 'silver surfer', I don't like to be asked to "remember" anything!
> 
> 
> > level:  000100
> >  we need^
> 
> 
> Consider:
> original_text (the contents of the .txt file - add buffering if volumes 
> are huge)
> current_text (the characters we have processed/"recognised" so-far)
> stack (what an original name for such a data-structure! Which will 
> contain each of the partial parenthetical expressions found - but yet to 
> be proven/made complete)
> 
> set current_text to NULSTRING
> for each current_character in original_text:
>   if current_character is LEFT_PARENTHESIS:
>   push current_text to stack
>   set current_text to LEFT_PARENTHESIS
>   concatenate current_character with current_text
>   if current_character is RIGHT_PARENTHESIS:
>   # current_text is a parenthetical expression
>   # do with it what you will
>   pop the stack
>   set current_text to the ex-stack string \
>   concat current_text's p-expn
> 
> Once working: cover 'special cases' (after above loop), eg original_text 
> which doesn't begin and/or end with parentheses; and error cases, eg 
> pop-ping a NULSTRING, or thinking things are finished but the stack is 
> not yet empty - likely events from unbalanced parentheses!
> 
> original text = "abc(def(gh))ij"
> 
> event 1: in-turn, concatenate characters "abc" as current_text
> event 2: locate (first) left-parenthesis, push current_text to stack(&)
> event 3: concatenate "(def"
> event 4: push, likewise
> event 5: concatenate "(gh"
> event 6: locate (first) right-parenthesis (matches to left-parenthesis 
> begining the current_string!)
> result?: ?print current_text?
> event 7: pop stack and redefine current_text as &

Re: Extract sentences in nested parentheses using Python

2019-12-05 Thread A S
On Tuesday, 3 December 2019 23:48:21 UTC+8, Peter Otten  wrote:
> A S wrote:
> 
> > On Tuesday, 3 December 2019 01:01:25 UTC+8, Peter Otten  wrote:
> >> A S wrote:
> >> 
> >> I think I've seen this question before ;)
> >> 
> >> > I am trying to extract all strings in nested parentheses (along with
> >> > the parentheses itself) in my .txt file. Please see the sample .txt
> >> > file that I have used in this example here:
> >> > (https://drive.google.com/open?id=1UKc0ZgY9Fsz5O1rSeBCLqt5dwZkMaQgr).
> >> > 
> >> > I have tried and done up three different codes but none of them seems
> >> > to be able to extract all the nested parentheses. They can only extract
> >> > a portion of the nested parentheses. Any advice on what I've done wrong
> >> > could really help!
> >> > 
> >> > Here are the three codes I have done so far:
> >> > 
> >> > 1st attempt:
> >> > 
> >> > import re
> >> > from os.path import join
> >> > 
> >> > def balanced_braces(args):
> >> > parts = []
> >> > for arg in args:
> >> > if '(' not in arg:
> >> > continue
> >> 
> >> There could still be a ")" that you miss
> >> 
> >> > chars = []
> >> > n = 0
> >> > for c in arg:
> >> > if c == '(':
> >> > if n > 0:
> >> > chars.append(c)
> >> > n += 1
> >> > elif c == ')':
> >> > n -= 1
> >> > if n > 0:
> >> > chars.append(c)
> >> > elif n == 0:
> >> > parts.append(''.join(chars).lstrip().rstrip())
> >> > chars = []
> >> > elif n > 0:
> >> > chars.append(c)
> >> > return parts
> >> 
> >> It's probably easier to understand and implement when you process the
> >> complete text at once. Then arbitrary splits don't get in the way of your
> >> quest for ( and ). You just have to remember the position of the first
> >> opening ( and number of opening parens that have to be closed before you
> >> take the complete expression:
> >> 
> >> level:  000100
> >> text:   abc(def(gh))ij
> >>when we are here^
> >> we need^
> >> 
> >> A tentative implementation:
> >> 
> >> $ cat parse.py
> >> import re
> >> 
> >> NOT_SET = object()
> >> 
> >> def scan(text):
> >> level = 0
> >> start = NOT_SET
> >> for m in re.compile("[()]").finditer(text):
> >> if m.group() == ")":
> >> level -= 1
> >> if level < 0:
> >> raise ValueError("underflow: more closing than opening
> >> parens")
> >> if level == 0:
> >> # outermost closing parenthesis:
> >> # deliver enclosed string including parens.
> >> yield text[start:m.end()]
> >> start = NOT_SET
> >> elif m.group() == "(":
> >> if level == 0:
> >> # outermost opening parenthesis: remember position.
> >> assert start is NOT_SET
> >> start = m.start()
> >> level += 1
> >> else:
> >> assert False
> >> if level > 0:
> >> raise ValueError("unclosed parens remain")
> >> 
> >> 
> >> if __name__ == "__main__":
> >> with open("lan sample text file.txt") as instream:
> >> text = instream.read()
> >> for chunk in scan(text):
> >> print(chunk)
> >> $ python3 parse.py
> >> ("xE'", PUT(xx..),"'")
> >> ("TRUuuuth")
> > 
> > Hello Peter! I tried this on my actual working files and it returned this
> > error: "unclosed parens remain". In this case, how can I continue to parse
> > through my text files by only extracting those with balanced parentheses
> > and ignore those that are incomplete?
> 
> filenames = ...
> for filename in filenames:
> with open(filename) as instream:
> text = instream.read()
> try:
> chunks = list(scan(text))
> except ValueError as err:
> print(f"{err} in file {filename!r}", file=sys.stderr)
> else:
>for chunk in chunks:
>print(chunk)

hey Peter, it works! Thank you :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Extract all words between two keywords in .txt file (Python)

2019-12-11 Thread A S
I would like to extract all words within specific keywords in a .txt file. For 
the keywords, there is a starting keyword of "PROC SQL;" (I need this to be 
case insensitive) and the ending keyword could be either "RUN;", "quit;" or 
"QUIT;". This is my sample .txt file.

Thus far, this is my code:

with open('lan sample text file1.txt') as file:
text = file.read()
regex = re.compile(r'(PROC SQL;|proc sql;(.*?)RUN;|quit;|QUIT;)')
k = regex.findall(text)
print(k)


Output:

[('quit;', ''), ('quit;', ''), ('PROC SQL;', '')]

However, my intended output is to get the words in between and inclusive of the 
keywords:

proc sql; ("TRUuuuth");
hhhjhfjs as fdsjfsj:
select * from djfkjd to jfkjs
(
SELECT abc AS abc1, abc_2_ AS efg, abc_fg, fkdkfj_vv, jjsflkl_ff, fjkdsf_jfkj
FROM &xxx..xxx_xxx_xxE
where ((xxx(xx_ix as format '-xx') gff &jfjfsj_jfjfj.) and 
  (xxx(xx_ix as format '-xx') lec &jgjsd_vnv.))
 );

1)

jj;

  select xx("xE'", PUT(xx..),"'") jdfjhf:jhfjj from _x_xx_L ;
quit; 

PROC SQL; ("CUuuuth");
hhhjhfjs as fdsjfsj:
select * from djfkjd to jfkjs
(SELECT abc AS abc1, abc_2_ AS efg, abc_fg, fkdkfj_vv, jjsflkl_ff, fjkdsf_jfkj
FROM &xxx..xxx_xxx_xxE
where ((xxx(xx_ix as format '-xx') gff &jfjfsj_jfjfj.) and 
  (xxx(xx_ix as format '-xx') lec &jgjsd_vnv.))(( ))
 );

2)(

RUN;


__
Any advice or different ways to go about this would be greatly appreciated!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract all words between two keywords in .txt file (Python)

2019-12-11 Thread A S
On Thursday, 12 December 2019 02:28:09 UTC+8, Ben Bacarisse  wrote:
> A S  writes:
> 
> > I would like to extract all words within specific keywords in a .txt
> > file. For the keywords, there is a starting keyword of "PROC SQL;" (I
> > need this to be case insensitive) and the ending keyword could be
> > either "RUN;", "quit;" or "QUIT;". This is my sample .txt file.
> >
> > Thus far, this is my code:
> >
> > with open('lan sample text file1.txt') as file:
> > text = file.read()
> > regex = re.compile(r'(PROC SQL;|proc sql;(.*?)RUN;|quit;|QUIT;)')
> > k = regex.findall(text)
> > print(k)
> 
> Try
> 
>   re.compile(r'(?si)(PROC SQL;.*(?:QUIT|RUN);)')
> 
> Read up one what (?si) means and what (?:...) means..  You can do the
> same by passing flags to the compile method.
> 
> > Output:
> >
> > [('quit;', ''), ('quit;', ''), ('PROC SQL;', '')]
> 
> Your main issue is that | binds weakly.  Your whole pattern tries to
> match any one of just four short sub-patterns:
> 
> PROC SQL;
> proc sql;(.*?)RUN;
> quit;
> QUIT;
> 
> -- 
> Ben.

Hey Ben, this works for my sample .txt file! Thanks:) but it wont work, if I 
have other multiple text files to parse through that, are similar but have some 
variations, strangely enough. 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Extract all words between two keywords in .txt file (Python)

2019-12-11 Thread A S
On Thursday, 12 December 2019 04:55:46 UTC+8, Joel Goldstick  wrote:
> On Wed, Dec 11, 2019 at 1:31 PM Ben Bacarisse  wrote:
> >
> > A S  writes:
> >
> > > I would like to extract all words within specific keywords in a .txt
> > > file. For the keywords, there is a starting keyword of "PROC SQL;" (I
> > > need this to be case insensitive) and the ending keyword could be
> > > either "RUN;", "quit;" or "QUIT;". This is my sample .txt file.
> > >
> > > Thus far, this is my code:
> > >
> > > with open('lan sample text file1.txt') as file:
> > > text = file.read()
> > > regex = re.compile(r'(PROC SQL;|proc sql;(.*?)RUN;|quit;|QUIT;)')
> > > k = regex.findall(text)
> > > print(k)
> >
> > Try
> >
> >   re.compile(r'(?si)(PROC SQL;.*(?:QUIT|RUN);)')
> >
> > Read up one what (?si) means and what (?:...) means..  You can do the
> > same by passing flags to the compile method.
> >
> > > Output:
> > >
> > > [('quit;', ''), ('quit;', ''), ('PROC SQL;', '')]
> >
> > Your main issue is that | binds weakly.  Your whole pattern tries to
> > match any one of just four short sub-patterns:
> >
> > PROC SQL;
> > proc sql;(.*?)RUN;
> > quit;
> > QUIT;
> >
> > --
> > Ben.
> > --
> > https://mail.python.org/mailman/listinfo/python-list
> 
> Consider using python string functions.
> 
> 1. read your string, lets call it s.
> 2 . start = s.find("PROC SQL:"
>  This will find the starting index point.  It returns and index
> 3. DO the same for each of the three possible ending  strings.  Use if/else
> 4. This will give you your ending index.
> 5 slice the included string, taking into account the start is start +
> len("PROC SQL;") and the end is the ending index - the length of
> whichever string ended in your case
> 
> Regular expressions are powerful, but not so easy to read unless you
> are really into them.
> -- 
> Joel Goldstick
> http://joelgoldstick.com/blog
> http://cc-baseballstats.info/stats/birthdays

Hey Joel, not too sure if i get the idea of your code implementation
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Fun with IO

2020-01-21 Thread Maxime S
Hi,

Le ven. 17 janv. 2020 à 20:11, Frank Millman  a écrit :


> It works perfectly. However, some pdf's can be large, and there could be
> concurrent requests, so I wanted to minimise the memory footprint. So I
> tried passing the client_writer directly to the handler -
>
>  await pdf_handler(client_writer)
>  client_writer.write(b'\r\n')
>
> It works! ReportLab accepts client_writer as a file-like object, and
> writes to it directly. I cannot use chunking, so I just let it do its
> thing.
>
> Can anyone see any problem with this?
>
>
If the socket is slower than the PDF generation (which is probably always
the case, unless you have a very fast network), it will still have to be
buffered in memory (in this case in the writer buffer). Since writer.write
is non-blocking but is not a coroutine, it has to buffer. There is an
interesting blog post about that here that I recommend reading:
https://lucumr.pocoo.org/2020/1/1/async-pressure/

Unfortunately, there is no way to avoid buffering the entire pdf in memory
without modifying reportlab to make it async-aware.

This version is still better than the one with BytesIO though because in
that version the pdf was buffered twice, once in BytesIO and once in the
writer, although you can fix that by using await writer.drain() after each
write and then the two versions are essentially equivalent.

Regards,

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


Help with oop

2020-02-22 Thread S Y
How can I use remove,add and verify methods in class oop. Which has tuple with 
allowed values inside class. Like two classes cart and inventory
Get Outlook for iOS
-- 
https://mail.python.org/mailman/listinfo/python-list


How to copy paragraphs (with number formatting) and images from Words (.docx) and paste into Excel (.xlsx) using Python

2020-03-22 Thread A S
I have contract clauses in Words (.docx) format that needs to be frequently 
copy and pasted into Excel (.xlsx) to be sent to the third party. The clauses 
are often updated hence there's always a need to copy and paste these clauses 
over. I only need to copy and paste all the paragraphs and images after the 
contents page. Here is a sample of the Clause document 
(https://drive.google.com/open?id=1ZzV29R6y2q0oU3HAVrqsFa158OhvpxEK).

I have tried doing up a code using Python to achieve this outcome. Here is the 
code that I have done so far:

!pip install python-docx
import docx
import xlsxwriter

document = docx.Document("Clauses Sample.docx")
wb = xlsxwriter.Workbook('C://xx//clauses sample.xlsx')

docText = []
index_row = 0
Sheet1 = wb.add_worksheet("Shee")

for paragraph in document.paragraphs:
if paragraph.text:
docText.append(paragraph.text)
xx = '\n'.join(docText)

Sheet1.write(index_row,0, xx)

index_row = index_row+1

wb.close()
#print(xx) 
However, my Excel file output looks like this:

I can't seem to paste pictures into this discussion so please see both my 
current and desired Excel output here:

https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to copy paragraphs (with number formatting) and images from Words (.docx) and paste into Excel (.xlsx) using Python

2020-03-22 Thread A S
On Monday, 23 March 2020 01:58:38 UTC+8, Beverly Pope  wrote:
> > On Mar 22, 2020, at 9:47 AM, A S  wrote:
> > 
> > I can't seem to paste pictures into this discussion so please see both my 
> > current and desired Excel output here:
> > 
> > https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an
> >  
> > <https://stackoverflow.com/questions/60800494/how-to-copy-paragraphs-with-number-formatting-and-images-from-words-docx-an>
> Did you try using the 2 part answer on the stackoverflow webpage?
> 
> Bev in TX

I'm able to get the paragraphs copied correctly now! But i'm trying to figure 
out if there's a way to copy and paste the images into the Excel, along with 
the paragraphs as well. Do you have an idea? :)
-- 
https://mail.python.org/mailman/listinfo/python-list


Regarding error code 9

2020-06-25 Thread Manikandan S
Sir/Mam;
  While installing matplotlib in python i face this issue that it shows
error : erro no 9 please reply with some solution for this error i am
beginner so please explain in detail about this error and guide me to fix
this error.

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


"OSError: [Errno 9] Bad file descriptor" When I try to Install the library in conda prompt

2020-07-21 Thread Mathiyazhagan S
Dear Sir/Madam,
I'm new to the python program.

I'm trying to install the "numby" or anything to add into the library by
using the windows command prompt I'm getting some error please find the
attachment.

So please help me to resolve this issue.


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


Re: Is there a log file that tracks every statement that is being executed when a program is running?

2020-10-25 Thread Maxime S
Hi,

You can use the trace module for that:
https://docs.python.org/3.8/library/trace.html

Personally I tend to put print statement at strategic places instead, I
find that easier to analyse than a full trace but YMMV.

Maxime


Le dim. 25 oct. 2020 à 01:25, Steve  a écrit :

> This would seriously help troubleshooting for me.  I updated a data file
> and
> now my main program is choking on it.  When the program encounters an
> error,
> it dumps a bit of information to the screen for a few steps before the
> error
> but that is not enough.
>
>
>
>
> Footnote:
> English sprakers on a roller coaster: "W"
> Spanish speakers on a rollercoaster:  " Nosostros"
>
> -Original Message-
> From: Python-list  On
> Behalf Of shrimp_banana
> Sent: Saturday, October 17, 2020 9:47 PM
> To: python-list@python.org
> Subject: Re: File Name issue
>
> On 10/17/20 4:12 PM, Steve wrote:
>  > The line:
>  > with open("HOURLYLOG.txt", 'r') as infile:
>  > works but, when I rename the file, the line:
>  > with open("HOURLY-LOG.txt", 'r') as infile:
>  > does not.  The complaint is: Cannot Assign to operator  >  > However, I
> have:
>  > BPM_O2s=open("BPM-O2-Readings.txt","a")
>  > And it works.
>  >
>  > At first, I thought the issue was due to having the - in the filename.
>  >
>  > Is there a fix or explanation for this?
>  > Steve
>
> I am unsure if this will help but you could try putting an r in front of
> the
> quotes to make it take raw data only.
> ie.
>
> with open(r"HOURLY-LOG.txt", 'r') as infile
> --
> https://mail.python.org/mailman/listinfo/python-list
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Windows process priority setting question...

2005-01-01 Thread Ray S
Is it possible to have an app re-set its own priority?
I see that 2.4+ has the ability for sub-processes, but only on creation.
Apparently
win32process.SetPriorityClass(handle, dwPriorityClass)
and
PyCWinThread.SetThreadPriority(priority)
allows one to change a sub while a the sub is running, but what about the 
current?

Ray
--
http://mail.python.org/mailman/listinfo/python-list


Re: The penis is way too delicate for masturbation

2005-09-01 Thread Eve S.

<[EMAIL PROTECTED]> schreef in bericht
news:[EMAIL PROTECTED]
> .
>

A decent amount of gentle sucking on the other hand never goes amiss.





-- 
sexy .sig wanted


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


Memory Allocation?

2005-02-06 Thread Chris S.
Is it possible to determine how much memory is allocated by an arbitrary 
Python object? There doesn't seem to be anything in the docs about this, 
but considering that Python manages memory allocation, why would such a 
module be more difficult to design than say, the GC?
--
http://mail.python.org/mailman/listinfo/python-list


Re: Memory Allocation?

2005-02-07 Thread Chris S.
Gerrit Holl wrote:
Chris S. wrote:
Is it possible to determine how much memory is allocated by an arbitrary 
Python object? There doesn't seem to be anything in the docs about this, 
but considering that Python manages memory allocation, why would such a 
module be more difficult to design than say, the GC?

Why do you want it?
It would seem desirable to know how the components of one's program 
occupies memory.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Memory Allocation?

2005-02-07 Thread Chris S.
M.E.Farmer wrote:
Hello Chris,
I am sure there are many inaccuracies in this story  but hey you asked
instead of seeking your owns answers so
In general you need not worry about  memory allocation.
Too be more specific objects have a size and most of them are known (at
least to a wizard named Tim) , but it doesn't really matter  because it
doesn't work like that in Python.
CPython interpreter( I have never read a lick of the source this all
from late nite memory  ) just grabs a chunk of memory and uses it as it
sees fit . Jython uses Java's GC . and etc..
Now tell me do you really want to take out the garbage or look at it?
Python does it for you so you don't have too.
Using similar logic, we shouldn't need access to the Garbage Collector 
or Profiler. After all, why would anyone need to know how fast their 
program is running or whether or not their garbage has been collected. 
Python takes care of it.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Memory Allocation?

2005-02-07 Thread Chris S.
Donn Cave wrote:
In article <[EMAIL PROTECTED]>,
 "Chris S." <[EMAIL PROTECTED]> wrote:

Is it possible to determine how much memory is allocated by an arbitrary 
Python object? There doesn't seem to be anything in the docs about this, 
but considering that Python manages memory allocation, why would such a 
module be more difficult to design than say, the GC?

Sorry, I didn't follow that - such a module as what?
GC == Garbage Collector (http://docs.python.org/lib/module-gc.html)
Along with the kind of complicated internal implementation
details, you may need to consider the possibility that the
platform malloc() may reserve more than the allocated amount,
for its own bookkeeping but also for alignment.  It isn't
a reliable guide by any means, but something like this might
be at least entertaining -
   >>> 
   >>> class A:
   ... def __init__(self, a):
   ... self.a = a
   ... 
   >>> d = map(id, map(A, [0]*32))
   >>> d.sort()
   >>> k = 0
   >>> for i in d:
   ... print i - k
   ... k = i
   ... 

This depends on the fact that id(a) returns a's storage
address.
I get very different results from one platform to another,
and I'm not sure what they mean, but at a guess, I think
you will see a fairly small number, like 40 or 48, that
represents the immediate allocation for the object, and
then a lot of intervals three or four times larger that
represent all the memory allocated in the course of creating
it.  It isn't clear that this is all still allocated -
malloc() doesn't necessarily reuse a freed block right
away, and in fact the most interesting thing about this
experiment is how different this part looks on different
platforms.  Of course we're still a bit in the dark as
to how much memory is really allocated for overhead.
   Donn Cave, [EMAIL PROTECTED]
Are you referring to Python's general method of memory management? I was 
under the impression that the ISO C specification for malloc() dictates 
allocation of a fixed amount of memory. free(), not malloc(), handles 
deallocation. Am I wrong? Does Python use a custom non-standard 
implementation of malloc()?
--
http://mail.python.org/mailman/listinfo/python-list


subprocess problem on Windows in IDLE and PythonWin

2005-02-15 Thread David S.
Python 2.4 on Windows XP
In the python command-line the following works fine:

>>> from subprocess import *
>>> p = Popen('dir', stdout=PIPE)

>From within IDLE or PythonWin I get the following exception:

Traceback (most recent call last):
  File "", line 1, in -toplevel-
p = Popen('dir', stdout=PIPE)
  File "c:\python24\lib\subprocess.py", line 545, in __init__
(p2cread, p2cwrite,
  File "c:\python24\lib\subprocess.py", line 605, in _get_handles
p2cread = self._make_inheritable(p2cread)
  File "c:\python24\lib\subprocess.py", line 646, in _make_inheritable
DUPLICATE_SAME_ACCESS)
TypeError: an integer is required

Note it works fine on Linux also.  I tested it with 
>>> p = Popen('ls', stdout=PIPE)
... and had no trouble.

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


Re: [newbie]How to install python under DOS and is there any Wxpython can be installed under dos?

2005-02-15 Thread David S.
john san  att.net> writes:

> 
> How to install python under DOS and is there any Wxpython-like can be
> installed under dos?
> 
> Thanks.
> 
If you are looking for Windows installers then, yes. See:
http://www.wxpython.org/
http://www.wxpython.org/download.php#binaries

If you are really looking for dos binaries, I guess you need to 
build them yourself.

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


huge help for interactive python

2005-02-16 Thread David S.
If you are using ipython on Windows then you will
have made sure you have Gary Bishop's readline 
library as instructed in the ipython install 
directions found at:
http://ipython.scipy.org/

Even if you use the standard commandline tool, 
installing readline makes the basic command line a 
lot easier to use.  (For some reason, I much
prefer it to IDLE or any of the other GUI-wrapped
interpreters.)

I could not find a list of the keyboard commands 
that readline supports, so I generated:

http://fsinnovations.net/share/keymap.pdf

NOTES:
You can checkout the script that generates this at:
http://fsinnovations.net/share/readlinekeymap.py
This uses Ken Seehof's Python Cookbook recipe found at:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/81982
I am sure it can be improved, but it was easy.  By the 
way, it generates LaTeK.

To install readline, get it at:
http://sourceforge.net/projects/uncpythontools.
You will also need the ctypes library by 
Thomas Heller, found at:
http://starship.python.net/crew/theller/ctypes



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


Re: huge help for interactive python

2005-02-16 Thread David S.
David S.  alumni.tufts.edu> writes:


> I am sure it can be improved, but it was easy.  By the 
> way, it generates LaTeK.

LaTeX, rather.

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


reuse validation logic with descriptors

2005-03-01 Thread David S.
I am looking for a way to implement the same simple validation on many 
instance attributes and I thought descriptors
(http://users.rcn.com/python/download/Descriptor.htm) looked like the 
right tool.  

But I am confused by their behavior on instance of my class. 
I can only get the approximate behavior by using class variables.

I am looking for something like:

class SingleChar(object):
def init(self):
self._char = None

def __set__(self, instance, value):
if not len(value) == 1:
raise ValueError
self._char = value

def __get__(self, instance, owner):
return self._char
   
class Flags(object):
def __init__(self):
self.a = SingleChar()
self.b = SingleChar()

f = Flags()
f.a = "a"
f.b = "bb"
exceptions.ValueError
ValueError:

What I actually get when I try this is f.a and f.b become str instances.

Meanwhile, I can get this to work, except that a and b are now just class
attributes.

class CFlags(object):
a = SingleChar()
b = SingleChar()

What is the proper and clean way to accomplish this sort of thing, so that you
can reuse the logic in for many instance attributes across multiple classes?

Thanks, David S.

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


Re: reuse validation logic with descriptors

2005-03-01 Thread David S.
Steven Bethard  gmail.com> writes:

> 
> David S. wrote:
> > I am looking for a way to implement the same simple validation on many 
> > instance attributes and I thought descriptors
> > (http://users.rcn.com/python/download/Descriptor.htm) looked like the 
> > right tool.  
> > 
> Looks like you're trying to reinvent the property descriptor.  Try using 
> the builtin property instead:
> 
> py> def getchar(self):
> ... if not hasattr(self, '_char'):
> ... self._char = None
> ... return self._char
> ...
> py> def setchar(self, value):
> ... if not len(value) == 1:
> ... raise ValueError
> ... self._char = value
> ...
> py> singlechar = property(getchar, setchar)
> py> class Flags(object):
> ... a = singlechar
> ... b = singlechar
> ...
> py> f = Flags()
> py> f.a = "a"
> py> f.b = "bb"
> Traceback (most recent call last):
>File "", line 1, in ?
>File "", line 3, in setchar
> ValueError
>
This still fails to work for instances variables of the class.  That is 
if I use your property in the following:
py> ...class Flags(object):
...def __init__(self): 
... a = singlechar
...
py> f = Flags()
py> f.a = "a"

Now f.a.__class__.__name__ returns 'str'.  So the property was not 
used at all.

Also, it seems that using a property, I can not do the other useful 
things I can do with a proper class, like provide an __init__, __str__, 
or __repr__.  

Again, thanks,
David S.


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


Re: reuse validation logic with descriptors

2005-03-01 Thread David S.
Steven Bethard  gmail.com> writes:
> 
> P.S.  If you haven't already, you should read 
> http://users.rcn.com/python/download/Descriptor.htm a couple of times. 
> It took me until about the third time I read it to really understand 
> what descriptors were doing.  The big thing to remember is that for an 
> instance b,
>  b.x
> is equivalent to
>  type(b).__dict__['x'].__get__(b, type(b))
> and for a class B,
>  B.x
> is equivalent to
>  B.__dict__['x'].__get__(None, B)
> Note that 'x' is always retrieved from the *type* __dict__, not from the 
> *instance* __dict__.

Steve, and others, thanks for the help.  This and Michael Spencer's reply
at http://article.gmane.org/gmane.comp.python.general/390478 have been very
helpful in getting the descriptor definition clear.  For me, it has taken 
reading http://users.rcn.com/python/download/Descriptor.htm about 4 times 
along with your help to get this straight.

Peace,
David S.

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


Re: reuse validation logic with descriptors

2005-03-02 Thread David S.
Steve Holden  holdenweb.com> writes:


> You want assignment to a method-local variable to turn an attribute into 
> a property? That's programming with a magic wand ...
>  
> That will depend on the value returned by property access, surely?
> 
> I suspect you are a little confused about properties and descriptors.
> 
> regards
>   Steve

Quite confused, actually, which was the reason for my original post.  
Thanks again to those who helped me and any other confused folks 
understand this bit of Python that much better.
Peace,
David S.


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


Re: global variables

2005-03-07 Thread David S.
M.N.A.Smadi  grads.ece.mcmaster.ca> writes:

> I need to have a  varaible that will contain a value that will be 
> modified in one file, and when coming back to the same file it 
> should retain the same value. 

You must import the module in which the variable lives and qualify it
appropriately.  

So, if you have the following files

trash1.py
var = 1

trash2.py
import trash1
trash1.var = 2

trash3.py
import trash1
print trash1.var

you can run the interpreter and:
>>>import trash2
>>>import trash3
2


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


Re: how to drop all thread ??

2004-11-29 Thread Chris S.
Leon wrote:
if class A(
use threading,thread module
) to produce 100 thread,how to drop its (100 thread) when its running 
As Roggisch suggests, the cleanest way is if the thread kills itself 
once signaled by an exit condition. However, there is a non-orthodox way 
of pseudo-forcibly killing threads by catching the kill signal in a 
traceback. This method is summed up in Connelly Barnes's informal 
KThread module:
http://www.google.com/groups?q=KThread+group:comp.lang.python&hl=en&lr=&selm=mailman.225.1083634398.25742.python-list%40python.org&rnum=1

Note it won't work in all cases, as it can't kill a thread that's made a 
blocking system call. However, it may come in useful.
--
http://mail.python.org/mailman/listinfo/python-list


Memory leak in python

2005-04-19 Thread Abhishek S
Hi,

using python2.2.2

I am seeing that the python application is very slowly
eating up the memory. i need help to indentify it.

It start with 11MB and keeps growing by 1 MB around
every 30mins.

#top | grep python
10351 root  15   0 26584  25M  3896 S 0.5  0.8
 46:05   1 python2
10351 root  15   0 26592  25M  3896 S 3.5  0.8
 46:06   1 python2
10351 root  15   0 26596  25M  3896 S30.9  0.8
 46:07   0 python2
10351 root  15   0 26608  25M  3896 S73.0  0.8
 46:11   0 python2
10351 root  15   0 26612  25M  3896 S73.2  0.8
 46:15   0 python2
10351 root  15   0 26616  25M  3896 S78.6  0.8
 46:18   1 python2
10351 root  15   0 26620  25M  3896 S78.4  0.8
 46:22   1 python2
10351 root  15   0 26620  25M  3896 S77.4  0.8
 46:26   1 python2
10351 root  15   0 26620  25M  3896 S73.2  0.8
 46:30   1 python2
10351 root  15   0 26620  25M  3896 S65.8  0.8
 46:33   1 python2
10351 root  15   0 26620  25M  3896 S43.3  0.8
 46:35   1 python2
10351 root  15   0 26620  25M  3896 S53.8  0.8
 46:38   1 python2
10351 root  15   0 26620  25M  3896 S26.3  0.8
 46:39   1 python2
10351 root  15   0 26636  26M  3896 S33.5  0.8
 46:41   1 python2
10351 root  15   0 26640  26M  3896 S25.7  0.8
 46:42   1 python2
10351 root  15   0 26656  26M  3896 S23.9  0.8
 46:44   1 python2
10351 root  15   0 26656  26M  3896 S11.7  0.8
 46:44   1 python2
10351 root  15   0 26660  26M  3896 S10.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 3.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 1.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 0.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 0.3  0.8
 46:45   1 python2
10351 root  15   0 26684  26M  3896 S 4.5  0.8
 46:45   1 python2
10351 root  15   0 26688  26M  3896 S 2.1  0.8
 46:45   1 python2

let me know how to approch this.
gc.collect - does not collect anything.


Thanks,
Abhishek

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
-- 
http://mail.python.org/mailman/listinfo/python-list


Fwd: Memory leak in python

2005-04-20 Thread Abhishek S
Hi Nick,

Thanks for reply... Please include me in reply.
Currently i am not in the list (i will subscribe soon)

I upgarded to 2.4.1 - still the same issue.

Nick>
Thats not a lot of leak - have you done that over a
longer time period?

Abhi>
I have tried for 4 days. It has reached 150MB.

Nick>
Are there any objects in gc.garbage?
>>> gc.set_debug(gc.DEBUG_LEAK)
>>> gc.get_debug( )
62
>>> gc.collect()
0
>>> gc.garbage
[]
>>>

Abhi>
There is none.

Nick>
Are you writing objects with __del__ methods?  If so
then that is your problem probably.

Abhi> 
I have not written any __del__ methods.

Nick>
Have you written any C extension modules in C?

Yes. Many - All of them are called only 
when the app starts. And never called again.
Till then it is stable only - 16MB used.

I have tried following - let me know if you need any
more details.. and want me to try something.

1)
I found a "sizer" python program. Which gives me the
module which is growing. It indicates that __main__ is
growing.

__main__': 4000774

2) I tried following.. (not smart but..)

def f():
 c = gc.get_objects()
 j = 0
 for i in c:
   j = j + 1
   try:
 tmp = len(i)
 if tmp > 1000:
  print "(c[%d]) (%d)," % (j-1, tmp)
   except:
 pass

it prints me as folows:

l(c[175]) (7336),
l(c[12475]) (1260),
l(c[12477]) (1260),
l(c[12479]) (1381),
l(c[12481]) (1381),
l(c[34159]) (1200),
l(c[37144]) (28234),
l(c[37191]) (28286),
>>> type(c[37191])

>>> for k,v in c[37164].items():
...print k, v
...b = b + 1
...if b > 30:
...   break
...
1085115764 620
1080048556 2
1085045932 4
1085146316 1
1085246700 2
1090615060 9
1089571940 2
1090519084 2
1090876932 234
1093456364 48
1085168140 2
1089964748 6
1089994828 0
1090095684 69
1076932268 2
1085014108 6
1080092204 10
108412 1
1118543628 48
1089994860 6
1076731524 6
1079640188 3
1084883076 15
1079712492 1
1118459244 64
1080295564 1
1076522028 4
1085211788 2
1076887700 20
1076729756 70
1091012236 2

This two dict in the last is growing slowly..
I am not maintaing any dict with such indices and
value.

Any clue? 
Please let me know what else to check and how!

At the time i am ending this.. module size..
'__main__': 7926830,

Thanks,
Abhishek

Note: forwarded message attached.


__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com --- Begin Message ---
Hi,

using python2.2.2

I am seeing that the python application is very slowly
eating up the memory. i need help to indentify it.

It start with 11MB and keeps growing by 1 MB around
every 30mins.

#top | grep python
10351 root  15   0 26584  25M  3896 S 0.5  0.8
 46:05   1 python2
10351 root  15   0 26592  25M  3896 S 3.5  0.8
 46:06   1 python2
10351 root  15   0 26596  25M  3896 S30.9  0.8
 46:07   0 python2
10351 root  15   0 26608  25M  3896 S73.0  0.8
 46:11   0 python2
10351 root  15   0 26612  25M  3896 S73.2  0.8
 46:15   0 python2
10351 root  15   0 26616  25M  3896 S78.6  0.8
 46:18   1 python2
10351 root  15   0 26620  25M  3896 S78.4  0.8
 46:22   1 python2
10351 root  15   0 26620  25M  3896 S77.4  0.8
 46:26   1 python2
10351 root  15   0 26620  25M  3896 S73.2  0.8
 46:30   1 python2
10351 root  15   0 26620  25M  3896 S65.8  0.8
 46:33   1 python2
10351 root  15   0 26620  25M  3896 S43.3  0.8
 46:35   1 python2
10351 root  15   0 26620  25M  3896 S53.8  0.8
 46:38   1 python2
10351 root  15   0 26620  25M  3896 S26.3  0.8
 46:39   1 python2
10351 root  15   0 26636  26M  3896 S33.5  0.8
 46:41   1 python2
10351 root  15   0 26640  26M  3896 S25.7  0.8
 46:42   1 python2
10351 root  15   0 26656  26M  3896 S23.9  0.8
 46:44   1 python2
10351 root  15   0 26656  26M  3896 S11.7  0.8
 46:44   1 python2
10351 root  15   0 26660  26M  3896 S10.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 3.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 1.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 0.7  0.8
 46:45   1 python2
10351 root  15   0 26668  26M  3896 S 0.3  0.8
 46:45   1 python2
10351 root  15   0 26684  26M  3896 S 4.5  0.8
 46:45   1 python2
10351 root  15   0 26688  26M  3896 S 2.1  0.8
 46:45   1 python2

let me know how to approch this.
gc.collect - does not collect anything.


Thanks,
Abhishek

__
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
--- End Message ---
-- 
http://mail.python.org/mailman/listinfo/python-list

Administrators and moderators of Python-list, please erase all the messages that I not should have posted here in python-list!

2015-12-10 Thread françai s
Administrators and moderators of Python-list, please erase all the messages
that I  not should have posted here in python-list.

I ask this because I probably be in future a good programmer famous and I
do not want to talk about the topics that I should not have posted here in
python-list.

I decided prevent substantial harm to important relationships that probably
I will have in future with other developers.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Question about asyncio and blocking operations

2016-01-28 Thread Maxime S
2016-01-28 17:53 GMT+01:00 Ian Kelly :

> On Thu, Jan 28, 2016 at 9:40 AM, Frank Millman  wrote:
>
> > The caller requests some data from the database like this.
> >
> >return_queue = asyncio.Queue()
> >sql = 'SELECT ...'
> >request_queue.put((return_queue, sql))
>
> Note that since this is a queue.Queue, the put call has the potential
> to block your entire event loop.
>
>
Actually, I don't think you actually need an asyncio.Queue.

You could use a simple deque as a buffer, and call fetchmany() when it is
empty, like that (untested):

class AsyncCursor:
"""Wraps a DB cursor and provide async method for blocking operations"""
def __init__(self, cur, loop=None):
if loop is None:
loop = asyncio.get_event_loop()
self._loop = loop
self._cur = cur
self._queue = deque()

def __getattr__(self, attr):
return getattr(self._cur, attr)

def __setattr__(self, attr, value):
return setattr(self._cur, attr, value)

async def execute(self, operation, params):
return await self._loop.run_in_executor(self._cur.execute,
operation, params)

async def fetchall(self):
return await self._loop.run_in_executor(self._cur.fetchall)


async def fetchone(self):
return await self._loop.run_in_executor(self._cur.fetchone)

async def fetchmany(self, size=None):
return await self._loop.run_in_executor(self._cur.fetchmany, size)


async def __aiter__(self):
return self

async def __anext__(self):
if self._queue.empty():
rows = await self.fetchmany()
if not rows:
raise StopAsyncIteration()
self._queue.extend(rows)

return self._queue.popleft()
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Cannot step through asynchronous iterator manually

2016-01-30 Thread Maxime S
2016-01-30 11:51 GMT+01:00 Frank Millman :

> "Chris Angelico"  wrote in message
> news:CAPTjJmoAmVNTCKq7QYaDRNQ67Gcg9TxSXYXCrY==s9djjna...@mail.gmail.com...
>
>
>> On Sat, Jan 30, 2016 at 7:22 PM, Frank Millman 
>> wrote:
>> > We had a recent discussion about the best way to do this, and ChrisA
>> > suggested the following, which I liked -
>> >
>> >cur.execute('SELECT ...)
>> >try:
>> >row = next(cur)
>> >except StopIteration:
>> ># row does not exist
>> >else:
>> >try:
>> >next_row = next(cur)
>> >except StopIteration:
>> ># row does exist
>> >else:
>> ># raise exception
>> >
>> > Now that I have gone async, I want to do the same with an asynchronous
>> > iterator.
>>
>
>
I might be a bit off-topic, but why don't you simply use cursor.rowcount?

For a pure iterator-based solution, I would do something like this (admitly
a bit cryptic, but iterator-based solutions often are :-) :

async def get_uniqu(ait):
async for row in ait:
break
else:
raise NotEnoughtRows()
async for _ in ait:
raise TooManyRows()
return row
-- 
https://mail.python.org/mailman/listinfo/python-list


Newbie suggestion: nice tutorial

2014-10-26 Thread Martin S
Even after having written three small tool for calculating chess
ratings, I felt that I severly lacked a proper understanding of what
the BEEP I was actually doing. So I looked at our standard bookshop at
work, found a book that I thought neat only to discover that our work
account has been cancelled...

So it was back to the internet - and this one seems pretty
comprehensive and understandable:

http://www.diveintopython3.net/

It doesn't cover the latest point version of Python (it's still Python
3), but I hope it doesn't matter much?


Regards,

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


[OFF-TOPIC] It is true that is impossible write in binary code, the lowest level of programming that you can write is in hex code?

2014-11-04 Thread françai s
I intend to write in lowest level of computer programming as a hobby.

It is true that is impossible write in binary code, the lowest level
of programming that you can write is in hex code?

What is the lowest level of programming computers that you can write ?

Is binary code?

Is hex code?

Is another machine code? Honestly do not know if it is true that there
is another machine code beyond the binary and hex code.

Is Assembly?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Broken IF statement

2015-01-13 Thread Maxime S
2015-01-12 22:19 GMT+01:00 :
>
> https://bpaste.net/show/93be9e15634b <--- Line 19 through 22
>
> At all times, my program is assigning the object priority of 0, even if
one already exists in the database with a priority of 0 (it's supposed to
be assigning it a priority of 1 in those cases).
>
> I'm a non developer trying to fix a freelancer's code. Would anybody be
able to suggest changes to the IF logic that might be able to fix it,
assuming the statements in the code provided look flawed?
>
> Thanks...
> --
> https://mail.python.org/mailman/listinfo/python-list


This line:

obj, created = SocialAccount.objects.get_or_create(...)

suggest you are using Django. If it is the case you have to add obj.save()
after changing the priority to send the new value to the DB.

Best,

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


subprocess command fails

2015-02-20 Thread Brad s
# cat makekeys.py
#!/usr/bin/python3.4
import subprocess
import sys
import string
import os.path
import datetime
import shlex
from time import gmtime, strftime
from subprocess import Popen, PIPE, STDOUT

pretime = strftime("%Y%m%d%H", gmtime())
time = datetime.datetime.strptime(pretime,'%Y%m%d%H')
print (time)
plustime = datetime.timedelta(days=730)
timeadd = (time + plustime)
str(timeadd)
#ndate = datetime.strptime(timeadd, '%Y%m%d%H')
#timeadd = timeadd.replace(tzinfo=UTC())
print (timeadd)

dname = input("Enter the domain to configure keys for? ")
if os.path.exists(dname+".external.signed"):
os.remove(dname+".external.signed")
#os.remove(dname+".external")
os.remove(dname+".ksk.key")
os.remove(dname+".zsk.key")
os.remove(dname+".ksk.private")
os.remove(dname+".zsk.private")
fd = open( dname+".external", 'w')
fd.write("$TTL 86400\n")
fd.write("$ORIGIN "+dname+".\n")
fd.write("@  1D  IN SOA yoda.ex-mailer.com.  admin@"+dname+".(\n")
fd.write("  "+strftime("%Y%m%d%H", gmtime())+"\n")
#fd.write(" "+repr(timeadd)+"\n")
fd.write("  3h\n")
fd.write("  1h\n")
fd.write("  1w\n")
fd.write("  1h)\n")
fd.write("  IN NS   yoda.ex-mailer.com.\n")
fd.write("  IN NS   r2d2.ex-mailer.com.\n")
fd.write(dname+".   IN TXT  v=spf1 mx a:r2d2.ex-mailer.com -all\n")
fd.write(dname+".   MX 0r2d2.ex-mailer.com.\n")
fd.write("mail."+dname+".   IN A107.191.60.48\n")
fd.write("$include /usr/local/etc/namedb/K"+dname+".zsk.key ; ZSK\n")
fd.write("$include /usr/local/etc/namedb/K"+dname+".ksk.key ; KSK\n")
fd.close()


result = subprocess.check_output(["dnssec-keygen", "-f", "KSK", "-r", 
"/dev/urandom", "-a", "RSASHA256", "-b", "2048", "-n", "ZONE", dname])
result_utf8 = result.decode("utf-8").strip()
mylist = list(result_utf8)
print (mylist[0])
listlen= len(mylist)
array = list()
listlen -= 11
i = 0
while( i < listlen ):
#if mylist != '\n' ^ mylist != '':
array.insert(i, mylist[i])
i = i + 1
combined = "".join(array)
print ('combined')
print (combined)
fmove = subprocess.call(["mv", result_utf8+".key",combined +".ksk.key"])
fmove = subprocess.call(["mv", result_utf8+".private",combined +".ksk.private"])

zresult = 
subprocess.check_output(["dnssec-keygen","-r","/dev/urandom","-a","RSASHA256","-b","2048","-n","ZONE",
 dname])
zresult_utf8 = zresult.decode("utf-8").strip()
myzlist = list(zresult_utf8)
print (myzlist[0])
zlistlen= len(myzlist)
zarray = list()
zlistlen -= 11
zi = 0
while( zi https://mail.python.org/mailman/listinfo/python-list


Re: subprocess command fails

2015-02-20 Thread Brad s
Yes, the program deletes the same files it produces. It looks to see if old 
stuff is there and if it exist, it deletes the files and creates and entirely 
new DNS zone with keys and then it is supposed to sign it.
The last step is where it is still failing but your code helped me to figure 
out why.
I am signing the zone with the current date/date (which is incorrect but was 
done for testing purposes.

I figured out how to add 2 years to the current data/time but I am unable to 
strip the formatting once I apply my + 2 years trick.

How can I add 2 years to stripped format date/time?


# dnssec-signzone -e2015022104 -p -t -g -k Ktest123.com.ksk.key -o 
test123.com test123.com.external Ktest123.com.zsk.key
dnssec-signzone: fatal: No self-signed KSK DNSKEY found.  Supply an active
key with the KSK flag set, or use '-P'.
# dnssec-signzone -e2016022104 -p -t -g -k Ktest123.com.ksk.key -o 
test123.com test123.com.external Ktest123.com.zsk.key
Verifying the zone using the following algorithms: RSASHA256.
Zone fully signed:
Algorithm: RSASHA256: KSKs: 1 active, 0 stand-by, 0 revoked
  ZSKs: 1 active, 0 stand-by, 0 revoked
test123.com.external.signed
Signatures generated:9
Signatures retained: 0
Signatures dropped:  0
Signatures successfully verified:0
Signatures unsuccessfully verified:  0
Signing time in seconds: 0.014
Signatures per second: 631.756
Runtime in seconds:  0.018



current code:

# cat makekeys.py
#!/usr/bin/python3.4
import subprocess
import sys
import string
import os.path
import datetime
import shlex
from time import gmtime, strftime
from subprocess import Popen, PIPE, STDOUT

pretime = strftime("%Y%m%d%H", gmtime())
time = datetime.datetime.strptime(pretime,'%Y%m%d%H')
print (time)
plustime = datetime.timedelta(days=730)
timeadd = (time + plustime)
str(timeadd)
#ndate = datetime.strptime(timeadd, '%Y%m%d%H')
#timeadd = timeadd.replace(tzinfo=UTC())
print (timeadd)

dname = input("Enter the domain to configure keys for? ")
if os.path.exists(dname+".external.signed"):
os.remove(dname+".external.signed")
#os.remove(dname+".external")
os.remove(dname+".ksk.key")
os.remove(dname+".zsk.key")
os.remove(dname+".ksk.private")
os.remove(dname+".zsk.private")
fd = open( dname+".external", 'w')
fd.write("$TTL 86400\n")
fd.write("$ORIGIN "+dname+".\n")
fd.write("@  1D  IN SOA yoda.ex-mailer.com.  admin@"+dname+".(\n")
fd.write("  "+strftime("%Y%m%d%H", gmtime())+"\n")
#fd.write(" "+repr(timeadd)+"\n")
fd.write("  3h\n")
fd.write("  1h\n")
fd.write("  1w\n")
fd.write("  1h)\n")
fd.write("  IN NS   yoda.ex-mailer.com.\n")
fd.write("  IN NS   r2d2.ex-mailer.com.\n")
fd.write(dname+".   IN TXT  v=spf1 mx a:r2d2.ex-mailer.com -all\n")
fd.write(dname+".   MX 0r2d2.ex-mailer.com.\n")
fd.write("mail."+dname+".   IN A107.191.60.48\n")
fd.write("$include /usr/local/etc/namedb/K"+dname+".zsk.key ; ZSK\n")
fd.write("$include /usr/local/etc/namedb/K"+dname+".ksk.key ; KSK\n")
fd.close()


result = subprocess.check_output(["dnssec-keygen", "-f", "KSK", "-r", 
"/dev/urandom", "-a", "RSASHA256", "-b", "2048", "-n", "ZONE", dname])
result_utf8 = result.decode("utf-8").strip()
mylist = list(result_utf8)
print (mylist[0])
listlen= len(mylist)
array = list()
listlen -= 11
i = 0
while( i < listlen ):
#if mylist != '\n' ^ mylist != '':
array.insert(i, mylist[i])
i = i + 1
combined = "".join(array)
print ('combined')
print (combined)
fmove = subprocess.call(["mv", result_utf8+".key",combined +".ksk.key"])
fmove = subprocess.call(["mv", result_utf8+".private",combined +".ksk.private"])

zresult = 
subprocess.check_output(["dnssec-keygen","-r","/dev/urandom","-a","RSASHA256","-b","2048","-n","ZONE",
 dname])
zresult_utf8 = zresult.decode("utf-8").strip()
myzlist = list(zresult_utf8)
print (myzlist[0])
zlistlen= len(myzlist)
zarray = list()
zlistlen -= 11
zi = 0
while( zi  # cat makekeys.py
> #!/usr/bin/python3.4
> import subprocess
> import sys
> import string
> import os.path
> import datetime
> import shlex
> from time import gmtime, strftime
> from subprocess import Popen, PIPE, STDOUT
> 
> pretime = strftime("%Y%m%d%H", gmtime())
> time = datetime.datetime.strptime(pretime,'%Y%m%d%H')
> print (time)
> plustime = datetime.timedelta(days=730)
> timeadd = (time + plustime)
> str(timeadd)
> #ndate = datetime.strptime(timeadd, '%Y%m%d%H')
> #timeadd = timeadd.replace(tzinfo=UTC())
> print (timeadd)
> 
> dname = input("Enter the domain to configure keys for? ")
> if os.path.exists(dname+".external.signed"):
> os.remove(dname+".external.signed")
> #os.remove(dname+".external")
>   

Re: subprocess command fails

2015-02-20 Thread Brad s
Time adjustment error:

# python3.4 timefix.py
2015022105
2015-02-21 05:00:00
Traceback (most recent call last):
  File "timefix.py", line 15, in 
ndate = datetime.datetime.strptime(timeadd, '%Y%m%d%H')
TypeError: must be str, not datetime.datetime



# cat timefix.py
#!/usr/bin/python3.4
import subprocess
import sys
from datetime import datetime
import datetime
from time import gmtime, strftime

pretime = strftime("%Y%m%d%H", gmtime())
time = datetime.datetime.strptime(pretime,'%Y%m%d%H')
print(pretime)
print (time)
plustime = datetime.timedelta(days=730)
timeadd = (time + plustime)
str(timeadd)
ndate = datetime.datetime.strptime(timeadd, '%Y%m%d%H')
#timeadd = timeadd.replace(tzinfo=UTC())
print (timeadd)
print (ndate)
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: subprocess command fails

2015-02-20 Thread Brad s
fixed with 

now = datetime.datetime.now()
later = now + datetime.timedelta(days=2*365)
striplater = later.strftime('%Y%m%d%H')




# python3.4 makekeys.py
Enter the domain to configure keys for? test1234.com
Generating key 
pair...+++
 
..+++
K
Generating key pair.+++ 
.+++
K
Verifying the zone using the following algorithms: RSASHA256.
Zone fully signed:
Algorithm: RSASHA256: KSKs: 1 active, 0 stand-by, 0 revoked
  ZSKs: 1 active, 0 stand-by, 0 revoked
test1234.com.external.signed
Signatures generated:9
Signatures retained: 0
Signatures dropped:  0
Signatures successfully verified:0
Signatures unsuccessfully verified:  0
Signing time in seconds: 0.010
Signatures per second: 883.392
Runtime in seconds:  0.013

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


SSH/Telnet program to Router/switch

2014-02-19 Thread Sujith S
Hi,

I am new to programming and python. I am looking for a python script to do 
ssh/telnet to a network equipment ? I know tcl/perl does this using 
expect/send. 

Do we have expect available in python as well or need to use some other method ?

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


Re: Yet Another Switch-Case Syntax Proposal

2014-04-06 Thread Marco S.
On 3 April 2014 20:12, Ian Kelly ian.g.kelly-at-gmail.com |
python-list@python.org|  wrote:
> Use this instead [of continue]:
>
> switch day case in ("Mon", "Tue", "Wed", "Thu", "Fri"):
> go_to_work = True
> day_type = "ferial"
> if day in ("Tue", "Thu"):
> lunch_time = datetime.time(11, 30)
> meeting_time = datetime.time(12, 30)
> else:
> lunch_time = datetime.time(12)
> meeting_time = datetime.time(14)
> case in ("Sat", "Sun"):
> go_to_work = False
> day_type = "festive"
>
> You get an extra level of indentation this way, but it reads less like
> spaghetti code.


Well, if you have to add an if-else to your switch-case, it means
switch-case syntax is not so useful.
An alternative is to imitate elif, so you'll have elcase. This way we don't
need continue. Since I do not like elcasein, the best solution is to do as
suggested by many of you, so case in instead of casein.
But if you can write case in, why you can't write "case" comp_operator in
general? With this syntax you can do also case is not, case > etc... Your
example will turn into

briefing_days = ("Tue", "Thu")
festive_days = ("Sat", "Sun")

switch day case in briefing_days:
lunch_time = datetime.time(11, 30)
meeting_time = datetime.time(12, 30)
case not in briefing_days + festive_days:
lunch_time = datetime.time(12)
meeting_time = datetime.time(14)
case in festive_days:
go_to_work = False
day_type = "festive"
else:
go_to_work = True
day_type = "ferial"

The if-else equivalent will be:

if day in briefing_days:
lunch_time = datetime.time(11, 30)
meeting_time = datetime.time(12, 30)
if day not in briefing_days + festive_days:
lunch_time = datetime.time(12)
meeting_time = datetime.time(14)
if day in festive_days:
go_to_work = False
day_type = "festive"
else:
go_to_work = True
day_type = "ferial"


If you don't specify comp_operator, the default is ==. Example:

switch day_num case 1:
day_str = "Monday"
elcase 2:
day_str = "Thursday"
else:
day_str = "etcetera"
-- 
https://mail.python.org/mailman/listinfo/python-list


implementing pyshark

2015-04-06 Thread Michael S.

Hi everyone. while trying to implement pyshark, i am getting this error:
   import pyshark
  capture = pyshark.LiveCapture(interface='wlan0')
  capture.sniff(timeout=50)
  capture
i have tried also to run it through interpreter yet, i got this error:
import pyshark
---
ImportError   Traceback (most recent call last)
 in ()
> 1 import pyshark

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-py2.7.egg/pyshark/__init__.py 
in ()

> 1 from pyshark.capture.live_capture import LiveCapture
  2 from pyshark.capture.file_capture import FileCapture
  3 from pyshark.capture.remote_capture import RemoteCapture
  4 from pyshark.capture.inmem_capture import InMemCapture

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-py2.7.egg/pyshark/capture/live_capture.py 
in ()

> 1 from pyshark.capture.capture import Capture
  2 from pyshark.tshark.tshark import get_tshark_interfaces
  3
  4
  5 class LiveCapture(Capture):

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-py2.7.egg/pyshark/capture/capture.py 
in ()

  1 from __future__ import unicode_literals
  2 import os
> 3 import logbook
  4 import sys
  5

/usr/local/lib/python2.7/dist-packages/logbook/__init__.py in ()
 12
 13
---> 14 from logbook.base import LogRecord, Logger, LoggerGroup, 
NestedSetup, \
 15  Processor, Flags, get_level_name, lookup_level, 
dispatch_record, \

 16  CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, NOTSET, \

/usr/local/lib/python2.7/dist-packages/logbook/base.py in ()
 16 from datetime import datetime
 17 from logbook import helpers
---> 18 from logbook.concurrency import thread_get_name, 
thread_get_ident, greenlet_get_ident

 19
 20 from logbook.helpers import to_safe_json, parse_iso8601, 
cached_property, \


/usr/local/lib/python2.7/dist-packages/logbook/concurrency.py in ()
 29
 30 if has_gevent:
---> 31 from gevent._threading import (Lock as ThreadLock,
 32RLock as ThreadRLock,
 33get_ident as thread_get_ident,

ImportError: No module named _threading

i tried importing threading first and importing pyshark, but the answer 
was the same.

any suggestions?
--
https://mail.python.org/mailman/listinfo/python-list


Re: implementing pyshark

2015-04-06 Thread Michael S.
I am using kali-linux(debian based). i have installed all from 
repository. i haven't tried yet to use the source but i don't think it 
was compiled incorrectly. Kali's developers are quite precise in terms 
of OS development.


On 04/06/2015 03:05 PM, Steven D'Aprano wrote:

On Mon, 6 Apr 2015 06:40 pm, Michael S. wrote:


Hi everyone. while trying to implement pyshark, i am getting this error:

[...]


ImportError: No module named _threading


Well that's awesome. I don't think I've seen that in Python 2.7 before.
Apparently, you are using a version of Python compiled without support for
threading. I didn't think that was still possible.

How did you install Python? Did you build it from source?

My guess is that you did build from source, but you were missing some
packages needed for threading support so the Python interpreter was built
without threading. That means you'll have to re-install to fix this
problem.

But first you'll need to install the necessary dependencies. What operating
system and/or distro are you using? It looks like Linux or Unix, or maybe
Mac OS X.




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


Re: implementing pyshark

2015-04-06 Thread Michael S.

import gevent --->  successful
import gevent._threading ---> fails
 output :
In [2]: import gevent._threading
---
ImportError   Traceback (most recent call last)
 in ()
> 1 import gevent._threading

ImportError: No module named _threading

In [3]: import gevent_threading
---
ImportError   Traceback (most recent call last)
 in ()
> 1 import gevent_threading

ImportError: No module named gevent_threading



On 04/06/2015 03:11 PM, Peter Otten wrote:

Michael S. wrote:


Hi everyone. while trying to implement pyshark, i am getting this error:
 import pyshark
capture = pyshark.LiveCapture(interface='wlan0')
capture.sniff(timeout=50)
capture
i have tried also to run it through interpreter yet, i got this error:
import pyshark


---

ImportError   Traceback (most recent call
last)  in ()
> 1 import pyshark

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-

py2.7.egg/pyshark/__init__.py

in ()
> 1 from pyshark.capture.live_capture import LiveCapture
2 from pyshark.capture.file_capture import FileCapture
3 from pyshark.capture.remote_capture import RemoteCapture
4 from pyshark.capture.inmem_capture import InMemCapture

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-

py2.7.egg/pyshark/capture/live_capture.py

in ()
> 1 from pyshark.capture.capture import Capture
2 from pyshark.tshark.tshark import get_tshark_interfaces
3
4
5 class LiveCapture(Capture):

/usr/local/lib/python2.7/dist-packages/pyshark-0.3.4-

py2.7.egg/pyshark/capture/capture.py

in ()
1 from __future__ import unicode_literals
2 import os
> 3 import logbook
4 import sys
5

/usr/local/lib/python2.7/dist-packages/logbook/__init__.py in ()
   12
   13
---> 14 from logbook.base import LogRecord, Logger, LoggerGroup,
NestedSetup, \
   15  Processor, Flags, get_level_name, lookup_level,
dispatch_record, \
   16  CRITICAL, ERROR, WARNING, NOTICE, INFO, DEBUG, NOTSET, \

/usr/local/lib/python2.7/dist-packages/logbook/base.py in ()
   16 from datetime import datetime
   17 from logbook import helpers
---> 18 from logbook.concurrency import thread_get_name,
thread_get_ident, greenlet_get_ident
   19
   20 from logbook.helpers import to_safe_json, parse_iso8601,
cached_property, \

/usr/local/lib/python2.7/dist-packages/logbook/concurrency.py in
()
   29
   30 if has_gevent:
---> 31 from gevent._threading import (Lock as ThreadLock,
   32RLock as ThreadRLock,
   33get_ident as thread_get_ident,

ImportError: No module named _threading

i tried importing threading first and importing pyshark, but the answer
was the same.
any suggestions?

Line 30 suggests that pyshark assumes that gevent is installed while line 31
indicates that gevent is not installed correctly.

So do you have an incomplete install of gevent? Either remove it or replace
it with a working one, i. e.

import gevent
import gevent._threading

should either both fail or both succeed.



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


Re: implementing pyshark

2015-04-06 Thread Michael S.



On 04/07/2015 03:55 AM, Steven D'Aprano wrote:

On Mon, 6 Apr 2015 10:45 pm, Michael S. wrote:


I am using kali-linux(debian based). i have installed all from
repository. i haven't tried yet to use the source but i don't think it
was compiled incorrectly. Kali's developers are quite precise in terms
of OS development.

What happens if you import threading?


If it returns without failure, then your Python interpreter is built
correctly with support for threading, and my guess was wrong.

If you get an error about no module _threading (or possibly _thread, I
forget which) then it is built without support for threading.

But, I'm now leaning towards thinking that Peter Otten's answer is more
likely. It seems to be gevent._threading that is missing. It wasn't
entirely clear from your original post, but in looking back I think Peter
is correct.

You should check whether you are accidentally shadowing gevent:

import gevent
print(gevent.__file__)


If that prints the file name of the actual gevent library, then it is
possible that you have a broken or outdated version of the library.

But if it is a file you have created, then you are shadowing the gevent
library, blocking Python from importing the library, it imports your
version instead. Rename your gevent.py file and the problem will hopefully
go away.




 Hi ,
i tried your suggestion: it did print the lib directory. - i tried 
removing the gevent deb-package and then installing  from src but got 
the same error.

I'll download other OS and will test it there.
--
https://mail.python.org/mailman/listinfo/python-list


Re: Function decorator having arguments is complicated

2015-04-27 Thread Maxime S
Le lun. 27 avr. 2015 à 04:39, Makoto Kuwata  a écrit :
>
> If function decorator notation could take arguments,
> decorator definition would be more simple:
>
>   def multiply(func, n):
> def newfunc(*args, **kwargs):
>   return n * func(*args, **kwargs)
> return newfunc
>
>   @multiply 4  # ex: @decorator arg1, arg2, arg3
>   def f1(x, y):
> return x+y
>
>
> How do you think about this idea?
>

David Beazley has a nice trick [1] to allow optional argument in decorators:

def logged(func=None, level=logging.DEBUG, message=None):
if func is None:
return partial(logged, level=level, message=message)

@wraps(func)
def wrapper(*args, **kwargs):
log.log(level, message)
return func(*args, **kwargs)
return wrapper

I think that solve your problem nicely, and that it is quite readable.

[1] Amongst a heap of other cool tricks, in his Python Cookbook

Regards,

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


bottle app "crashes"

2015-07-06 Thread Martin S
Hi all,

Last summer I fumbled together a small appplication that calculates both LASK 
and Elo ratings for chess. I managed to "webify" it using Bottle. This works 
nicely on my laptop for testing.

However ... (you knew there would be a however right)

Once I log off (or my user session times out) my server where I've started the 
application with python3 LASKweb.py & the application dies within a  minute, 
resulting in clients getting 404 errors when accessing the page (a simple 
table that's processed by the application).

I've tried installting bottle deamon but I keep getting errors to the effect 
that it doesn't recognize bottledeamon.
Also I've tried to run as a wsgi application, but I seem to missunderstand 
what modifications I need to do the get it to run (I get server 
misconfiguration errors on the latter).

Do anyone have a pointer to an idiot proof instruction on how to deploy a 
simple bottle application to a live server.

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


Re: bottle app "crashes"

2015-07-08 Thread Martin S
On Monday 06 July 2015 21.57.21 Jason Friedman wrote:
> > Last summer I fumbled together a small appplication that calculates both
> > LASK and Elo ratings for chess. I managed to "webify" it using Bottle.
> > This works nicely on my laptop for testing.
> > 
> > Once I log off (or my user session times out) my server where I've started
> > the application with python3 LASKweb.py & the application dies within a 
> > minute, resulting in clients getting 404 errors when accessing the page
> > (a simple table that's processed by the application).
> 
> Similar to other answers here, I do not know why your application
> stops serving, but I have had success using waitress
> (https://pypi.python.org/pypi/waitress) with bottle
> (http://bottlepy.org/docs/dev/deployment.html#switching-the-server-backend).

Now it seems to be working properly. Thanks all.

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


GOTCHA with list comprehension

2015-08-04 Thread Pavel S
Hi,

I recently found interesting GOTCHA while doing list comprehension in python 
2.6:

>>> values = ( True, False, 1, 2, 3, None )
>>> [ value for value in values if value if not None ]
[True, 1, 2, 3]

I was wondering why this list comprehension returns incorrect results and 
finally found a typo in the condition. The typo wasn't visible at the first 
look.

My intention was: if value is not None
But I wrote: if value if not None

Is that a language feature of list comprehension that it accepts conditions 
like: if A if B if C if D ...?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
It seems this is allowed by the grammar:

list_display::=  "[" [expression_list | list_comprehension] "]"
list_comprehension  ::=  expression list_for
list_for::=  "for" target_list "in" old_expression_list [list_iter]
old_expression_list ::=  old_expression [("," old_expression)+ [","]]
old_expression  ::=  or_test | old_lambda_expr
list_iter   ::=  list_for | list_if
list_if ::=  "if" old_expression [list_iter]

So chaining multiple ifs is fine:

[ i for i in range(10) if True if True if True if True ]

Dne středa 5. srpna 2015 8:49:20 UTC+2 Pavel S napsal(a):
> Hi,
> 
> I recently found interesting GOTCHA while doing list comprehension in python 
> 2.6:
> 
> >>> values = ( True, False, 1, 2, 3, None )
> >>> [ value for value in values if value if not None ]
> [True, 1, 2, 3]
> 
> I was wondering why this list comprehension returns incorrect results and 
> finally found a typo in the condition. The typo wasn't visible at the first 
> look.
> 
> My intention was: if value is not None
> But I wrote: if value if not None
> 
> Is that a language feature of list comprehension that it accepts conditions 
> like: if A if B if C if D ...?

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


Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
$ cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.5 (Santiago)
$ python --version
Python 2.6.6

> Incidentally, why Python 2.6?
> 
> ChrisA


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


  1   2   3   4   5   6   7   8   >