Opening multiple Files in Different Encoding
Dear Group, I kept a good number of files in a folder. Now I want to read all of them. They are in different formats and different encoding. Using listdir/glob.glob I am able to find the list but how to open/read or process them for different encodings? If any one can help me out.I am using Python3.2 on Windows. Regards, Subhabrata Banerjee. -- http://mail.python.org/mailman/listinfo/python-list
Calling Values
Dear Group, I am trying to call the values of one function in the another function in the following way: def func1(): num1=10 num2=20 print "The Second Number is:",num2 return def func2(): num3=num1+num2 num4=num3+num1 print "New Number One is:",num3 print "New Number Two is:",num4 return I am preferring not to use argument passing or using class? Is there any alternate way? Thanking in Advance, Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Some Silly Questions
Dear Group, I am going to ask two very silly questions, if any one can kindly tell me why this structure is taken? classifier.pseudocode(depth=4) from nltk.corpus import brown Sorry to ask you these. Actually everytime I get confused with the answers. Regards, Subhabrata -- http://mail.python.org/mailman/listinfo/python-list
Re: Python and Hidden Markov Model
On Mar 8, 7:29 pm, Oscar Benjamin wrote: > On 8 March 2013 05:26, wrote: > > > On Friday, March 8, 2013 2:18:06 AM UTC+5:30, [email protected] wrote: > > >> I was trying to learn Hidden Markov Model. In Python there are various > >> packages, but I was willing to do some basic calculation starting from the > >> scratch so that I can learn the model very aptly. Do you know of any thing > >> such? > > > My problem is over model validation on continuous time Markov system. > > Generally, I understand the theory and can run the kits like HMM.py or > > Scikit-learn. > > The problem is if I can not fit the data in run time I would be at the > > mercy of the kit. > > So I wanted to know the coding of the computation. > > If those projects can do what you want then why not just look at their code? > > > I am specifically looking at the small python example of Forward, Backward > > and Viterbi > > calculation. I tried to surf the web but did not help much. > > How about these two (both in > Python):http://en.wikipedia.org/wiki/Viterbi_algorithm#Examplehttp://en.wikipedia.org/wiki/Forward%E2%80%93backward_algorithm#Pytho... > > > I do not know much of Scientific forum. > > Try scipy-user as a start (someone there may know of a better mailing > list):http://mail.scipy.org/mailman/listinfo/scipy-user > > > I thought as HMM.py, NLTK, Scikit-learn are Python implementations so there > > would be lot > > of people in the room who would know it. > > And I got people like you, so I can not say I am wrong! > > Python as a programming language is used for many different things. I > doubt that many people on this list will know what a Hidden Markov > Model is. While I do know what they are, I have never done anything > with them in Python or otherwise. However, if you ask in the right > place, I'm sure that you will find people who have done similar things > in Python. > > Oscar Thank you Sir for your kind time. I would surely check them. Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Use of index
Dear All, I have a small question. If I have code line like the following: a1="God" a2="God is always great" a3=a2.index(a1) a4=a2.find(a1) a5=a2.split() a6=a5.index(a1) a7=a5.find(a1) # Invalid as find is applicable only in string but not in list. if a4>-1: print "God may be always great" -- Now, my q is can we use index like find? Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Question on Joining of list
Dear Group,
I am trying the following code line:
def try2(n):
a1=raw_input("PRINT A STRING:")
a2=a1.split()
a3="God Godess Heaven Sky"
for x in a2:
a4=a3.find(x)
if a4>-1:
a5=a3[a4]
print a5
elif a4<0:
a6=x
print "It is not found"
print a6
else:
print "Error"
s=a5+" "+a6
print s
Here, if I put a string like:
Petrol Helium Heaven Sky
In s it is giving me S Helium
But I am looking for an output of a5 and a6 concatenating all its
values not the last ones. Can you suggest me any help? Am I missing
any minor point?
Best Regards,
Subhabrata.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question on Joining of list
Sorry if I didn't say that.
The input is a string "Petrol Helium Heaven Sky"
Now, in a3 it is "God Goddess Heaven Sky" is there,
it is matching Heaven and Sky but not Petrol and Helium as they are
not in a3.
Now, as per the code it is giving me an output "S" of "Sky" and
"Helium"
But I was looking for an output of "H S Petrol Helium" and not "S
Helium" meaning all the values of a5 and a6 will be concatenated in s.
Best Regards,
Subhabrata..
Marc 'BlackJack' Rintsch wrote:
> On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
>
> > def try2(n):
> > a1=raw_input("PRINT A STRING:")
> > a2=a1.split()
> > a3="God Godess Heaven Sky"
> > for x in a2:
> > a4=a3.find(x)
> > if a4>-1:
> > a5=a3[a4]
> > print a5
> > elif a4<0:
> > a6=x
> > print "It is not found"
> > print a6
> > else:
> > print "Error"
> > s=a5+" "+a6
> > print s
> >
> > Here, if I put a string like:
> > Petrol Helium Heaven Sky
> > In s it is giving me S Helium
> > But I am looking for an output of a5 and a6 concatenating all its
> > values not the last ones. Can you suggest me any help? Am I missing
> > any minor point?
>
> Maybe you should describe what the input looks like and what output you
> want to have and how the input and output are connected. In words, not in
> not very clear code with "numbered names". That's a silly idea and makes
> understanding the code very hard. Please use meaningful names!
>
> Ciao,
> Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question on Joining of list
Thanx Peter,
I would change my variables next time I would post. And obviously,
thanx for your solution. I am reviewing it, I was also trying out some
solutions.
Best Regards,
Subhabrata.
Peter Otten wrote:
> SUBHABRATA wrote:
>
> > I am trying the following code line:
>
> def try2(n):
> user_line = raw_input("PRINT A STRING:")
> user_words = user_line.split()
> my_line = "God Godess Heaven Sky"
> for word in user_words:
> pos = my_line.find(word)
> if pos >- 1:
> first_char = my_line[pos]
> print first_char
> elif pos < 0:
> missing_word = word
> print "It is not found"
> print missing_word
> else:
> print "Error"
> s = first_char + " " + missing_word
> print s
>
> try2(1)
>
> Do you recognise your code? With that jumpstart you should find the error in
> no time ;)
>
> > Here, if I put a string like:
> > Petrol Helium Heaven Sky
> > In s it is giving me S Helium
> > But I am looking for an output of a5 and a6 concatenating all its
> > values not the last ones. Can you suggest me any help? Am I missing
> > any minor point?
>
> Yes, use meaningful variables. They won't make your code magically correct
> but will make it a lot easier to pinpoint mistakes and false assumptions --
> for you and others.
>
> Peter
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question on Joining of list
Hi Peter,
In your code s would print first_char(of the last word)+"
"+missing_word(the last word) I was looking all.
Best Regards,
Subhabrata.
SUBHABRATA wrote:
> Sorry if I didn't say that.
> The input is a string "Petrol Helium Heaven Sky"
> Now, in a3 it is "God Goddess Heaven Sky" is there,
> it is matching Heaven and Sky but not Petrol and Helium as they are
> not in a3.
> Now, as per the code it is giving me an output "S" of "Sky" and
> "Helium"
> But I was looking for an output of "H S Petrol Helium" and not "S
> Helium" meaning all the values of a5 and a6 will be concatenated in s.
> Best Regards,
> Subhabrata..
>
> Marc 'BlackJack' Rintsch wrote:
> > On Fri, 18 Jul 2008 01:31:59 -0700, SUBHABRATA wrote:
> >
> > > def try2(n):
> > > a1=raw_input("PRINT A STRING:")
> > > a2=a1.split()
> > > a3="God Godess Heaven Sky"
> > > for x in a2:
> > > a4=a3.find(x)
> > > if a4>-1:
> > > a5=a3[a4]
> > > print a5
> > > elif a4<0:
> > > a6=x
> > > print "It is not found"
> > > print a6
> > > else:
> > > print "Error"
> > > s=a5+" "+a6
> > > print s
> > >
> > > Here, if I put a string like:
> > > Petrol Helium Heaven Sky
> > > In s it is giving me S Helium
> > > But I am looking for an output of a5 and a6 concatenating all its
> > > values not the last ones. Can you suggest me any help? Am I missing
> > > any minor point?
> >
> > Maybe you should describe what the input looks like and what output you
> > want to have and how the input and output are connected. In words, not in
> > not very clear code with "numbered names". That's a silly idea and makes
> > understanding the code very hard. Please use meaningful names!
> >
> > Ciao,
> > Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question on Joining of list
Hi Peter, Peter Otten wrote: > SUBHABRATA wrote: > > > Thanx Peter, > > I would change my variables next time I would post. > > No, you should use meaningful variable names when you write your code no > matter whether you plan to post it or not. Good You are teaching me something good in life. Thanx. > > > And obviously, > > thanx for your solution. I am reviewing it, I was also trying out some > > solutions. > > You misunderstood. I did not modify your code other than changing the > variable names. My hope was that with this modification any errors sprang > to you eye... I was seeing that. I am almost near the solution. You can also try some hands if you feel. Best Regards, Subhabrata. > > Peter -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Joining of list
Thanx Terry it worked, I was thinking if input_string could be searched from given_string and replaced in the input_string but your one is smarter. And Peter, thanx for trying to teach conventions. But if I write explicit comments, and carry on using my own variables( I can use anything as they are variables:-) ) according to my own ease isn't that good? Best Regards, Subhabrata. MRAB wrote: > On Jul 19, 6:34�am, Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > > On Fri, 18 Jul 2008 16:43:35 -0700 (PDT), John Machin > > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > > > > > > > > The only language I remember that had implicit typing was FORTRAN (GOD > > > is real, but JESUS is an integer). > > > > Hadn't seen that one before -- maybe because I learned FORTRAN IV at a > > college in the middle of west Michigan; I think half the population was > > one step away from turning Amish > > > > I learned it by the word: Indian -- implicit integers began at I, and > > ended with N. > > > You could've just used the first 2 letters of 'integer'! :-) -- http://mail.python.org/mailman/listinfo/python-list
Web Page Construction in Python
Dear Group, I am getting some questions on doing Web Pages in Python. I have some interactive codes in python for which I like to make web pages. I am trying to use kid. Kid I learnt, and is easy, too. My questions are: i) Am I going correct? ii) Is there any language other than kid? iii)The worked out examples of kid are not opening properly, is there any other URL where I can see them. iv) Can cgi scripting be done with kid? If any one can spend time on my questions. Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Question Regarding XML
Dear Group, I have some queries regarding XML conversion of some .txt/.doc files. I am thinking to use Satine. Is it OK? But it seems to support Python2.3 but does it support 2.5, too? If any one can kindly let me know. Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Problem with list.insert
Dear Group,
I wrote one program,
There is a dictionary.
There is an input string.
Every word of input string the word is matched against the dictionary
If the word of input string is matched against the dictionary it gives
the word of the dictionary.
But if it does not find it gives the original word.
After searching the words are joined back.
But as I am joining I am finding the words which are not available in
dictionary are printed in the last even if the word is given in the
first/middle.
Now, I want to take them in order.
I am applying a thumb rule that the position of the word of the string
is exact with the resultant string.
So, I am determining the word which is not in the dictionary, and its
position in the input string.
Now I am inserting it in the target string, for this I am splitting
both the given string and the output/result string.
Till now it is working fine.
But a problem happening is that if I insert it it is inserting same
words multiple times and the program seems to be an unending process.
What is the error happening?
If any one can suggest.
The code is given below:
import re
def wordchecker1(n):
# INPUTTING STRING
a1=raw_input("PRINT ONE ENGLISH SENTENCE FOR DICTIONARY CHECK:")
#CONVERTING TO LOWER CASE
a2=a1.lower()
#CONVERTING INTO LIST
a3=a2.split()
#DICTIONARY
a4=open("/python25/Changedict3.txt","r")
a5=a4.read()
a6=a5.split()
found=[]
not_found=[]
#SEARCHING DICTIONARY
for x in a3:
a7="\n"
a8=a7+x
if a8 in a5:
a9=a5.index(a8)
a10=a5[a9:]
a11=re.search("\xe0.*?\n",a10)
a12=a11.group()
a13=a12[:-1]
found.append(a13)
elif a8 not in a5:
a14=x
not_found.append(a14)
else:
print "Error"
found.extend(not_found)
# THE OUTPUT
print "OUTPUT STRING IS"
a15=(' '.join(found))
#THE OUTPUT STRING
print a15
# SPLITTING OUTPUT STRING IN WORDS
a16=a15.split()
#TAKING OUT THE WORD FROM OUTPUT STRING
for word in a16:
#MATCHING WITH GIVEN STRING
a17=a2.find(word)
if a17>-1:
print "The word is found in the Source String"
a18=a3.index(word)
a19=a3[a18]
print a19
#INSERTING IN THE LIST OF TARGET STRING
a20=a16.insert(a18,a19)
print a16
a21=(" ".join(a16))
print a21
Best Regards,
Subhabrata.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Problem with list.insert
Some people in the room told I am kidding, but I learnt Python from
Python docs which gives examples like these,
But I write explicit comments,
an excerpt from python docs:
# Measure some strings:
... a = ['cat', 'window', 'defenestrate']
>>> for x in a:
... print x, len(x)
...
cat 3
window 6
defenestrate 12
But well, if you are suggesting improvement I'll surely listen.
The outputs are given in Hindi, it is a dictionary look up program,
the matching words are in Hindi, you may leave aside them.
How to debug the result string is to see the words which are in
English as the group page does not take italics so I am putting one
asterisk* after it
NO PROBLEM:
INPUT:
he has come
OUTPUT IS
उओह/ उन्होने रहेसाक्ता २.यात्राकरना
PROBLEM:
INPUT:
(i) Lincoln* has come
OUTPUT IS:
रहेसाक्ता २.यात्राकरना lincoln*
lincoln lincoln* रहेसाक्ता २.यात्राकरना lincoln
lincoln lincoln* lincoln* रहेसाक्ता २.यात्राकरना lincoln
….and increasing the number and seems a never ending process.
MY EXPEPECTED STRING IS:
lincoln रहेसाक्ता २.यात्राकरना lincoln^
The latter places marked^ I am editing don't worry for that,
though MY FINAL EXPECTED STRING IS:
lincoln रहेसाक्ता २.यात्राकरना
Best Regards,
Subhabrata.
Marc 'BlackJack' Rintsch wrote:
> On Thu, 28 Aug 2008 09:13:00 -0700, SUBHABRATA wrote:
>
> > import re
> > def wordchecker1(n):
> > # INPUTTING STRING
> > a1=raw_input("PRINT ONE ENGLISH SENTENCE FOR DICTIONARY CHECK:")
> > #CONVERTING TO LOWER CASE
> > a2=a1.lower()
> > #CONVERTING INTO LIST
> > a3=a2.split()
> > #DICTIONARY
> > a4=open("/python25/Changedict3.txt","r") a5=a4.read()
> > a6=a5.split()
> > found=[]
> > not_found=[]
> >#SEARCHING DICTIONARY
> > for x in a3:
> > a7="\n"
> > a8=a7+x
> > if a8 in a5:
> > a9=a5.index(a8)
> > a10=a5[a9:]
> > a11=re.search("\xe0.*?\n",a10)
> > a12=a11.group()
> > a13=a12[:-1]
> > found.append(a13)
> > elif a8 not in a5:
> > a14=x
> > not_found.append(a14)
> > else:
> > print "Error"
> > found.extend(not_found)
> > # THE OUTPUT
> > print "OUTPUT STRING IS"
> > a15=(' '.join(found))
> > #THE OUTPUT STRING
> > print a15
> > # SPLITTING OUTPUT STRING IN WORDS
> > a16=a15.split()
> > #TAKING OUT THE WORD FROM OUTPUT STRING for word in a16:
> > #MATCHING WITH GIVEN STRING
> > a17=a2.find(word)
> > if a17>-1:
> > print "The word is found in the Source String"
> > a18=a3.index(word)
> > a19=a3[a18]
> > print a19
> > #INSERTING IN THE LIST OF TARGET STRING
> > a20=a16.insert(a18,a19)
> > print a16
> > a21=(" ".join(a16))
> > print a21
>
> a1, a2, a2, …, a20? You must be kidding. Please stop numbering names
> and use *meaningful* names instead!
>
> Could you describe them problem better, with sample inputs and expected
> outputs. There must be a better way that that unreadable mess above.
>
> Ciao,
> Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list
Re: Problem with list.insert
Dear group,
Thanx for your idea to use dictionary instead of a list. Your code is
more or less, OK, some problems are there, I'll debug them. Well, I
feel the insert problem is coming because of the Hindi thing.
And Python2.5 is supporting Hindi quite fluently.
I am writing in Python2.5.1.
Best Regards,
Subhabrata.
Terry Reedy wrote:
> SUBHABRATA, I recommend you study this excellent response carefully.
>
> castironpi wrote:
> > On Aug 28, 11:13 am, SUBHABRATA <[EMAIL PROTECTED]> wrote:
> >-.
> >
> > Instead split up your inputs first thing.
> >
> > trans= { 'a': 'A', 'at': 'AT', 'to': 'TO' }
> > sample= 'a boy at the park walked to the tree'
> > expected= 'A boy AT the park walked TO the tree'
>
> It starts with a concrete test case -- an 'executable problem
> statement'. To me, this is cleared and more useful than the 20 lines of
> prose you used. A single line English statement would be "Problem:
> Replace selected words in a text using a dictionary." Sometimes, less
> (words) really is more (understanding).
>
> If the above is *not* what you meant, then give a similarly concrete
> example that does what you *do* mean.
>
> > sample_list= sample.split( )
> > for i, x in enumerate( sample_list ):
> > if x in trans:
> > sample_list[ i ]= trans[ x ]
>
> Meaningful names make the code easy to understand. Meaningless numbered
> 'a's require each reader to create meaningful names and associate them
> in his/her head. But that is part of the job of the programmer.
>
> > result= ' '.join( sample_list )
> > print result
> > assert result== expected
>
> It ends with an automated test that is easy to rerun should the code in
> between need to be modified. Assert only prints something if there is
> an error. With numerous tests, that is what one often wants. But with
> only one, your might prefer 'print' instead of 'assert' to get a more
> reassuring and satisfying 'True' printed.
>
> > Then replace them as you visit each one, and join them later.
>
> If you are using Hindi characters, you might want to use Python3 when it
> arrives, since it will use Unicode strings as the (default) string type.
> But for posting here, stick with the ascii subset.
>
> Terry Jan Reedy
--
http://mail.python.org/mailman/listinfo/python-list
Question on Open Project
Dear Room, I am a python programmer, from India(New Delhi area), and was in Bangalore for long days. My specialization is Natural Language Processing, -Machine Learning(worked on Naive Bayes, SVM, HMM, CRF). I am looking for some open projects in Python-in Machine Learning/NLP area, preferably from India(as many a times personal interaction is helpful) which I can do from home. If anyone knows of any reliable link. Best, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: Looking for Remote Python Project
On Feb 1, 8:45 am, Alan Meyer wrote: > On 01/29/2011 04:19 PM,joy99wrote: > > > Dear Room, > > > I am a Python Programmer from India(New Delhi Region), and I worked > > for quite a long time in Bangalore. I have been working in Python for > > the last 4 years or so. I have successfully built around 15 projects > > in Python. I am looking for some remote Python Projects, which can be > > done from home. > > > If any one knows of anything, I may be helpful enough. > > > Best Regards, > > Subhabrata. > > Subharata, > > Would you be willing to tell us what a programmer with your level of > experience typically charges per hour for his services? > > I'm not in a position to hire anyone, I'm just a programmer myself. But > I'm curious about rates in India vs. the U.S., where I live and work. > > Thanks and good luck with your efforts to get work. > > Alan Alan, Usually if any one pays USD 1 per hr in India it is good, USD 2 per hour is handsome, very rare people pay USD 3 to 4 per hour, but I know some people in India charge USD 20/25 per line I do not know their hourly rate but as I know they just run some consultancy and do not do any job. The people who give in range of USD 1-4/hr also gives some perks like performance related bonus, housing, medical, etc. But again rate varies. Delhi/Gurgaon gives highest pay, followed by Bangalore/Hyderabad, then comes Chennai, Mumbai gives moderate, Kolkata/Mysore/Bhubaneswar are casual players, they neither have serious places of work nor any good environment. In India, lots of development goes on in the government sector but right now they are paying very high, generally they pay 20-30% lower than private sector, but job security is there. Hope this information helps. Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Enthought Canopy
Hi, I was trying to download Python2.7 in a new machine. I found Python2.7.9. I tried to install few libraries like Numpy, Sympy, Scipy, NLTK etc. I was trying to use http://www.lfd.uci.edu/~gohlke/pythonlibs/ to download the libraries. Initially there were some problems to download Numpy. So tried to get Canopy from https://www.enthought.com/products/canopy/package-index/, and found it also has IDLE as GUI. I found numpy, scipy there. Now I saw if I install the .whl files I can install it in Canopy and use it from the IDLE available there. These files are not getting installed in my original Python library and I am not finding them in the original Python GUI. May I use Enthought based Python2.7 and its associated GUI for developing software or should I migrate and use the Python2.7 library and its associated GUI? If anyone of the members may kindly suggest. Regards, Subhabrata. -- https://mail.python.org/mailman/listinfo/python-list
How to handle file in Whoosh?
I am trying to build a search engine, I started with Whoosh. The tutorial and
web based materials are fine. Web has sizable question and answers. The initial
experiments seem going fine. But I want to handle files located in various
parts of my machine. I found "from whoosh.filedb.filestore import FileStorage",
but I am looking for a simple example to start with. I tried something as
below, it may be giving some result but is it going okay? If any one may please
see and correct if required?
>>> txt_file1=open("/python27/whooshtext1.txt","r").read()
>>> txt_file2=open("/python27/whooshtext3.txt","r").read()
>>> writer.add_document(title=u"First document", path=
>>> unicode("indexdir"+os.sep+"a"),content=u"txt_file1")
>>> writer.add_document(title=u"Second document", path=
>>> unicode("indexdir"+os.sep+"b"),content=u"txt_file2")
>>> writer.commit()
>>> with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse("flood")
results = searcher.search(query)
print results
for result in results:
print result
>>>
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to convert .doc file to .txt in Python
On Thursday, April 9, 2015 at 4:23:55 PM UTC+5:30, Tim Golden wrote:
> On 09/04/2015 11:25, wrote:
> > Dear Group,
> >
> > I was trying to convert .doc file to .txt file.
> >
> > I got of python-docx, zipfile but they do not seem to help me much.
> >
> > You may kindly suggest how to convert from .doc to
> > .docx/.html/.pdf/.rtf as from them I am being able to convert to
> > .txt.
> >
> > If any one of the Python experts may kindly help me.
>
>
> There are several approaches, but this one will work (assuming you are
> on Windows and have the pywin32 package installed):
>
>
> import os
> import win32com.client
>
> DOC_FILEPATH = "c:/temp/something.docx"
> doc = win32com.client.GetObject(DOC_FILEPATH)
> text = doc.Range().Text
>
> #
> # do something with the text...
> #
> with open("something.txt", "wb") as f:
> f.write(text.encode("utf-8"))
>
> os.startfile("something.txt")
>
>
>
> TJG
Thanks Tim it is slightly better than my solution.
--
https://mail.python.org/mailman/listinfo/python-list
Re: How to convert .doc file to .txt in Python
On Thursday, April 9, 2015 at 3:56:09 PM UTC+5:30, [email protected] wrote: > Dear Group, > > I was trying to convert .doc file to .txt file. > > I got of python-docx, zipfile but they do not seem to help me much. > > You may kindly suggest how to convert from .doc to .docx/.html/.pdf/.rtf as > from them I am being able to convert to .txt. > > If any one of the Python experts may kindly help me. > > Regards, > Subhabrata Banerjee. I could do one it seems running with >>> import win32com.client as win32 >>> word = win32.Dispatch("Word.Application") >>> word.Visible = 0 >>> word.Documents.Open("/python27/Document1.doc") >>> doc = word.ActiveDocument seems working. You may suggest better. -- https://mail.python.org/mailman/listinfo/python-list
How to convert .doc file to .txt in Python
Dear Group, I was trying to convert .doc file to .txt file. I got of python-docx, zipfile but they do not seem to help me much. You may kindly suggest how to convert from .doc to .docx/.html/.pdf/.rtf as from them I am being able to convert to .txt. If any one of the Python experts may kindly help me. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Converting text file to different encoding.
I am having few files in default encoding. I wanted to change their encodings,
preferably in "UTF-8", or may be from one encoding to any other encoding.
I was trying it as follows,
>>> import codecs
>>> sourceEncoding = "iso-8859-1"
>>> targetEncoding = "utf-8"
>>> source = open("source1","w")
>>> target = open("target", "w")
>>> target.write(unicode(source, sourceEncoding).encode(targetEncoding))
but it was giving me error as follows,
Traceback (most recent call last):
File "", line 1, in
target.write(unicode(source, sourceEncoding).encode(targetEncoding))
TypeError: coercing to Unicode: need string or buffer, file found
If anybody may kindly suggest how may I solve it.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Converting text file to different encoding.
On Friday, April 17, 2015 at 6:50:08 PM UTC+5:30, [email protected] wrote: > I am having few files in default encoding. I wanted to change their > encodings, > preferably in "UTF-8", or may be from one encoding to any other encoding. > > I was trying it as follows, > >>>> import codecs >>>> sourceEncoding = "iso-8859-1" >>>> targetEncoding = "utf-8" >>>> source = open("source1","w") >>>> target = open("target", "w") >>>> target.write(unicode(source, sourceEncoding).encode(targetEncoding)) > > but it was giving me error as follows, > Traceback (most recent call last): > File "", line 1, in > target.write(unicode(source, sourceEncoding).encode(targetEncoding)) > TypeError: coercing to Unicode: need string or buffer, file found > > If anybody may kindly suggest how may I solve it. > > Regards, > Subhabrata Banerjee. As an ace coder you may know better than me what I would need, but if you have any roundabout or hint you may give I will practice to see if I may port it. -- https://mail.python.org/mailman/listinfo/python-list
Re: Converting text file to different encoding.
On Friday, April 17, 2015 at 7:36:46 PM UTC+5:30, Oscar Benjamin wrote:
> wrote:
> > On Friday, April 17, 2015 at 6:50:08 PM UTC+5:30, wrote:
> >> I am having few files in default encoding. I wanted to change their
> >> encodings,
> >> preferably in "UTF-8", or may be from one encoding to any other encoding.
> >>
> >> I was trying it as follows,
> >>
> >>>>> import codecs
> >>>>> sourceEncoding = "iso-8859-1"
> >>>>> targetEncoding = "utf-8"
> >>>>> source = open("source1","w")
> >>>>> target = open("target", "w")
> >>>>> target.write(unicode(source, sourceEncoding).encode(targetEncoding))
> >>
> >> but it was giving me error as follows,
> >> Traceback (most recent call last):
> >> File "", line 1, in
> >> target.write(unicode(source, sourceEncoding).encode(targetEncoding))
> >> TypeError: coercing to Unicode: need string or buffer, file found
>
> The error comes from `unicode(source, sourceEncoding)` and results
> from the fact that source is a file object when it should be a string.
> To read the contents of the file as a string just change `source` to
> `source.read()`.
>
>
> Oscar
I tried to do as follows,
>>> import codecs
>>> sourceEncoding = "iso-8859-1"
>>> targetEncoding = "utf-8"
>>> source = open("source1","w")
>>> string1="String type"
>>> str1=str(string1)
>>> source.write(str1)
>>> source.close()
>>> target = open("target", "w")
>>> source=open("source1","r")
>>> target.write(unicode(source.read(), sourceEncoding).encode(targetEncoding))
>>>
am I going ok?
--
https://mail.python.org/mailman/listinfo/python-list
Opening Multiple files at one time
Dear Group, I am trying to open multiple files at one time. I am trying to do it as, for item in [ "one", "two", "three" ]: f = open (item + "world.txt", "w") f.close() This is fine. But I was looking if I do not know the number of text files I would create beforehand, so not trying xrange option also. And if in every run of the code if the name of the text files have to created on its own. Is there a solution for this? If anybody may please suggest. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Opening Multiple files at one time
On Tuesday, April 21, 2015 at 4:20:16 AM UTC+5:30, Dave Angel wrote: > On 04/20/2015 07:59 AM, wrote: > > Dear Group, > > > > I am trying to open multiple files at one time. > > I am trying to do it as, > > > > for item in [ "one", "two", "three" ]: > > f = open (item + "world.txt", "w") > > f.close() > > > > This is fine. > > But it does not open multiple files at one time. Perhaps you'd better > explain better what you mean by "at one time." > > > But I was looking if I do not know the number of > > text files I would create beforehand, > > So instead of using a literal list [ "one", "two... ] > you construct one, or read it in from disk, or use sys.argv. What's the > difficulty? Nothing in the code fragment you show cares how long the > list is. > > > so not trying xrange option > > also. > > No idea what "the xrange option" means. > > > > > And if in every run of the code if the name of the text files have > > to created on its own. > > So figure out what you're going to use for those names, and write the > code to generate them. > > > > > Is there a solution for this? > > For what? > > > -- > DaveA Yes. They do not. They are opening one by one. I have some big chunk of data I am getting by crawling etc. now as I run the code it is fetching data. I am trying to fetch the data from various sites. The contents of the file are getting getting stored in separate files. For example, if I open the site of "http://www.theguardian.com/international";, then the result may be stored in file in file "file1.txt", and the contents of site "http://edition.cnn.com/";, may be stored in file "file2.txt". But the contents of each site changes everyday. So everyday as you open these sites and store the results, you should store in different text files. These text files I am looking to be created on its own, as you do not know its numbers, how many numbers you need to fetch the data. I am trying to do some results with import datetime as datetime.datetime.now() may change everytime. I am trying to put it as name of file. But you may suggest better. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Opening Multiple files at one time
On Monday, April 20, 2015 at 5:30:15 PM UTC+5:30, [email protected] wrote: > Dear Group, > > I am trying to open multiple files at one time. > I am trying to do it as, > > for item in [ "one", "two", "three" ]: >f = open (item + "world.txt", "w") >f.close() > > This is fine. But I was looking if I do not know the number of > text files I would create beforehand, so not trying xrange option > also. > > And if in every run of the code if the name of the text files have > to created on its own. > > Is there a solution for this? > > If anybody may please suggest. > > Regards, > Subhabrata Banerjee. Surely, this problem is more or less fixed. But I experiment with all answers everytime to get better angles. -- https://mail.python.org/mailman/listinfo/python-list
A question on the creation of list of lists
Dear Group,
I am trying to open a bunch of files from a directory and trying to put the
results in list of lists that is to say,
that is to say,
I have a list of file names of a directory, I want to read each one of them.
After reading each one of them, I want to put the results of each file in a
list.
These lists would again be inserted to create a list of lists.
to do this I am trying to write it as follows:
list_of_files = glob.glob('C:\Python27\*.*')
print list_of_files
list1=[]
list2=[]
list_N=[list1,list2]
for i,j in zip(list_of_files,list_N):
print i,j
x1=open(i,"r").read()
x2=j.append(x1)
all_sent=list_N
print all_sent
Am I doing anything wrong? If any one may kindly suggest?
Is there any smarter way to do it? I am using Python2.7+
on MS-Windows 7 Professional Edition.
Apology for any indentation error.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: A question on the creation of list of lists
On Wednesday, April 22, 2015 at 9:48:44 PM UTC+5:30, [email protected] wrote: > Dear Group, > > I am trying to open a bunch of files from a directory and trying to put the > results in list of lists that is to say, > > that is to say, > I have a list of file names of a directory, I want to read each one of them. > After reading each one of them, I want to put the results of each file in a > list. > These lists would again be inserted to create a list of lists. > > to do this I am trying to write it as follows: > > list_of_files = glob.glob('C:\Python27\*.*') > print list_of_files > list1=[] > list2=[] > list_N=[list1,list2] > for i,j in zip(list_of_files,list_N): > print i,j > x1=open(i,"r").read() > x2=j.append(x1) > all_sent=list_N > print all_sent > > Am I doing anything wrong? If any one may kindly suggest? > Is there any smarter way to do it? I am using Python2.7+ > on MS-Windows 7 Professional Edition. > Apology for any indentation error. > > Regards, > Subhabrata Banerjee. I was trying to get some results over small data before putting heavy data, code seems giving desired output, as in The name of files are: ['C:\\Python27\\TestDoc\\TestDoc1.txt', 'C:\\Python27\\TestDoc\\TestDoc2.txt', 'C:\\Python27\\TestDoc\\TestDoc3.txt', 'C:\\Python27\\TestDoc\\TestDoc4.txt'] C:\Python27\TestDoc\TestDoc1.txt [] C:\Python27\TestDoc\TestDoc2.txt [] C:\Python27\TestDoc\TestDoc3.txt [] C:\Python27\TestDoc\TestDoc4.txt [] The Contents of file in list of lists: [['There is a home.'], ['One man lives there.'], ['He is tall.'], ['He is good.']] I am trying to put heavy files with big contents, so was getting confused whether I was going fine. But the way I am creating lists may there be a a better way? Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
May I drop list bracket from list?
Dear Group,
I am trying to read a list of files as
list_of_files = glob.glob('C:\Python27\*.*')
Now I am trying to read each one of them,
convert into list of words, and append to a list
as.
list1=[]
for file in list_of_files:
print file
fread1=open(file,"r").read()
fword=fread1.split()
list1.append(fword)
Here the list is a list of lists, but I want only one list not
list of lists.
I was thinking of stripping it as, str(list1).strip('[]')
but in that case it would be converted to string.
Is there a way to do it. I am using Python27 on Windows7 Professional.
Apology for an indentation error.
If anybody may please suggest.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: May I drop list bracket from list?
On Thursday, April 23, 2015 at 3:57:28 PM UTC+5:30, Peter Otten wrote:
>
>
> > Dear Group,
> >
> > I am trying to read a list of files as
> > list_of_files = glob.glob('C:\Python27\*.*')
> > Now I am trying to read each one of them,
> > convert into list of words, and append to a list
> > as.
> >
> > list1=[]
> > for file in list_of_files:
> > print file
> > fread1=open(file,"r").read()
> > fword=fread1.split()
> > list1.append(fword)
> >
> > Here the list is a list of lists, but I want only one list not
> > list of lists.
> >
> > I was thinking of stripping it as, str(list1).strip('[]')
> >
> > but in that case it would be converted to string.
> >
> > Is there a way to do it. I am using Python27 on Windows7 Professional.
> > Apology for an indentation error.
> >
> > If anybody may please suggest.
>
> You have to understand that the append() method always appends a single item
> to the list, be that a string or a list or whatever. If you want to append
> words in a list to the list the logical approach is therefore to loop over
> the words and invoke append for every word
>
> for word in fword:
> list1.append(word)
>
> There is also a dedicated extend() method that takes a list (actually an
> iterable) and appends all items in that list:
>
> list1.extend(fword)
Thanks Peter. I tried an example,
>> ll = [['a'], ['b'], ['c']]
>>> l = [x for y in ll for x in y]
I would try your one,too.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Boolean Search using Strings
Dear Group, I want to do the Boolean search over various sentences or documents. I do not want to use special programs like Whoosh, etc. May I use any other parser? If anybody may kindly let me know. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Boolean Operator Confusion
Dear Group,
I am trying to understand the use of Boolean operator in Python. I am trying to
write small piece of script, as follows,
def input_test():
str1=raw_input("PRINT QUERY:")
if "AND" or "OR" or "NOT" in str1:
print "It is a Boolean Query"
elif "AND" or "OR" or "NOT" not in str1:
print "It is not a Boolean Query"
else:
print "None"
I am trying to achieve if the words "AND","OR","NOT" ... in string I want to
recognize it as,
Boolean Query, if they are not there the string is not Boolean query.
As I am trying to test it I am getting following output,
>>> input_test()
PRINT QUERY:obama AND clinton
It is a Boolean Query
>>> input_test()
PRINT QUERY:obama clinton
It is a Boolean Query
To understand Boolean operators I have tried to read the follwing link,
https://docs.python.org/release/2.5.2/lib/boolean.html
and practised script like the following:
>>> def currency(n):
x1=raw_input("PRINT Your Country")
x2=raw_input("Print Your Currency")
if x1=="USA" and x2=="Dollar":
print "Correct"
elif x1=="USA" and x2!="Dollar":
print "Not Matching"
else:
print "None"
>>> currency(1)
PRINT Your CountryUSA
Print Your CurrencyDollar
Correct
>>>
But I am doing something wrong. If anybody may kindly suggest.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Boolean Operator Confusion
On Friday, April 24, 2015 at 8:45:04 PM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 25 Apr 2015 12:50 am,wrote:
>
> > Dear Group,
> >
> > I am trying to understand the use of Boolean operator in Python. I am
> > trying to write small piece of script, as follows,
> >
> > def input_test():
> > str1=raw_input("PRINT QUERY:")
> > if "AND" or "OR" or "NOT" in str1:
> > print "It is a Boolean Query"
> > elif "AND" or "OR" or "NOT" not in str1:
> > print "It is not a Boolean Query"
> > else:
> > print "None"
>
> First problem: why do you sometimes return "None"? You have two possible
> answers: either something is a boolean query, or it is not. There is no
> third choice. ("It's a boolean query, but only on Wednesdays.")
>
> So your code you have if...else and no "elif" needed.
>
> if :
> print "It is a Boolean Query"
> else:
> print "It is not a Boolean Query"
>
>
> Now let us look at your test for a boolean query:
>
> "AND" or "OR" or "NOT" in str1
>
>
> How does a human reader understand that as English?
>
> if "AND" is in the string, or "OR" is in the string, or "NOT"
> is in the string, then it is a boolean query.
>
> But sadly, that is not how Python sees it. Python sees it as:
>
> if "AND" is a true value, or if "OR" is a true value,
> or if "NOT" is in the string, then it is a boolean query.
>
> "AND" is always a true value. All strings except for the empty string "" are
> true values, so expressions like:
>
> if X or Y or Z in some_string
>
> will always be true, if X or Y are true values.
>
> You need to re-write your test to be one of these:
>
> # version 1
> if "AND" in str1 or "OR" in str1 or "NOT" in str1:
> print "It is a Boolean Query"
> else:
> print "It is not a Boolean Query"
>
>
> # version 2
> if any(word in str1 for word in ("AND", "OR", "NOT")):
> print "It is a Boolean Query"
> else:
> print "It is not a Boolean Query"
>
>
>
>
> --
> Steven
Thanks Steven for taking so much of your valuable time to make me understand
and nice guidance. Ian your suggestion worked well. Thank you. Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Accessing file from Remote location
Dear Group,
I have a good amount of data in a remote location.
It is in MySql Database. I am trying to access it as,
>>> import pymysql
>>> import pymysql.cursors
...
...
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT candidateid,cnd.FirstName,
cnd.LastName,Concat('\\xxx.xxx.x.xxx\files\Cand_Res/',orgguid,'/',DATE_FORMAT(cnd.createddate,'%Y%m'),'/',candidateguid,'/',File)
as filePath from candidate cnd join mstorganization org on cnd.orgid =
org.OrgId order by cnd.modifieddate limit 1"
cursor.execute(sql)
result = cursor.fetchone()
print(result)
Now I am getting the file path.
I am trying to open this file in Python.
I tried options as,
f=open("//remote_machine/folder1/file1.doc", "r"),
f=open("remote_machine\\folder1\\file1.doc", "r")
...
given in
https://mail.python.org/pipermail/python-win32/2009-February/008847.html
and in
http://www.thecodingforums.com/threads/how-to-open-a-remote-file-using-python.671892/
but I am not being able to open it.
Am I doing any error?
If I run the path I am getting the document.
My document path is:
\\xxx.xxx.x.xxx\Files\Cand_Res/0FB45CD9-B9E3-4ED5-BBD0-B0EA3DA62B2E/201308/da0791ba-b123-4cfc-ac1e-5a42af2091d8/2f14e4b3-4fb8-4e5f-bcb8-f5d34ee9ab8d.doc
I am using Python 2.7.6 | 64-bit | (default, Sep 15 2014, 17:36:35) [MSC v.1500
64 bit (AMD64)] on win32 Enthought
Canopy. This is not my default Python location.
My current directory is:
>>> os.getcwd()
'C:\\Windows\\system32'
>>>
I am using Windows 7 Professional 64 bit.
If any body may kindly suggest.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Fast way of extracting files from various folders
Dear Group,
I have several millions of documents in several folders and subfolders in my
machine.
I tried to write a script as follows, to extract all the .doc files and to
convert them in text, but it seems it is taking too much of time.
import os
from fnmatch import fnmatch
import win32com.client
import zipfile, re
def listallfiles2(n):
root = 'C:\Cand_Res'
pattern = "*.doc"
list1=[]
for path, subdirs, files in os.walk(root):
for name in files:
if fnmatch(name, pattern):
file_name1=os.path.join(path, name)
if ".doc" in file_name1:
#EXTRACTING ONLY .DOC FILES
if ".docx" not in file_name1:
#print "It is A Doc file$$:",file_name1
try:
doc = win32com.client.GetObject(file_name1)
text = doc.Range().Text
text1=text.encode('ascii','ignore')
text_word=text1.split()
#print "Text for Document File Is:",text1
list1.append(text_word)
print "It is a Doc file"
except:
print "DOC ISSUE"
But it seems it is taking too much of time, to convert to text and to append to
list. Is there any way I may do it fast? I am using Python2.7 on Windows 7
Professional Edition. Apology for any indentation error.
If any one may kindly suggest a solution.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Fast way of extracting files from various folders
On Friday, May 1, 2015 at 5:58:50 PM UTC+5:30, [email protected] wrote: > Dear Group, > > I have several millions of documents in several folders and subfolders in my > machine. > I tried to write a script as follows, to extract all the .doc files and to > convert them in text, but it seems it is taking too much of time. > > import os > from fnmatch import fnmatch > import win32com.client > import zipfile, re > def listallfiles2(n): > root = 'C:\Cand_Res' > pattern = "*.doc" > list1=[] > for path, subdirs, files in os.walk(root): > for name in files: > if fnmatch(name, pattern): > file_name1=os.path.join(path, name) > if ".doc" in file_name1: > #EXTRACTING ONLY .DOC FILES > if ".docx" not in file_name1: > #print "It is A Doc file$$:",file_name1 > try: > doc = win32com.client.GetObject(file_name1) > text = doc.Range().Text > text1=text.encode('ascii','ignore') > text_word=text1.split() > #print "Text for Document File Is:",text1 > list1.append(text_word) > print "It is a Doc file" > except: > print "DOC ISSUE" > > But it seems it is taking too much of time, to convert to text and to append > to list. Is there any way I may do it fast? I am using Python2.7 on Windows 7 > Professional Edition. Apology for any indentation error. > > If any one may kindly suggest a solution. > > Regards, > Subhabrata Banerjee. Thanks. You are right conversions are taking time. I would surely check. Rest part is okay. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Fast way of extracting files from various folders
On Saturday, May 2, 2015 at 2:52:32 PM UTC+5:30, Peter Otten wrote:
> wrote:
>
> > I have several millions of documents in several folders and subfolders in
> > my machine. I tried to write a script as follows, to extract all the .doc
> > files and to convert them in text, but it seems it is taking too much of
> > time.
> >
> > import os
> > from fnmatch import fnmatch
> > import win32com.client
> > import zipfile, re
> > def listallfiles2(n):
> > root = 'C:\Cand_Res'
> > pattern = "*.doc"
> > list1=[]
> > for path, subdirs, files in os.walk(root):
> > for name in files:
> > if fnmatch(name, pattern):
> > file_name1=os.path.join(path, name)
> > if ".doc" in file_name1:
> > #EXTRACTING ONLY .DOC FILES
> > if ".docx" not in file_name1:
> > #print "It is A Doc file$$:",file_name1
> > try:
> > doc = win32com.client.GetObject(file_name1)
> > text = doc.Range().Text
> > text1=text.encode('ascii','ignore')
> > text_word=text1.split()
> > #print "Text for Document File Is:",text1
> > list1.append(text_word)
> > print "It is a Doc file"
> > except:
> > print "DOC ISSUE"
> >
> > But it seems it is taking too much of time, to convert to text and to
> > append to list. Is there any way I may do it fast? I am using Python2.7 on
> > Windows 7 Professional Edition. Apology for any indentation error.
> >
> > If any one may kindly suggest a solution.
>
> It will not help the first time through your documents, but if you write the
> words for the word documents in one .txt file per .doc, and the original
> files rarely change you can read from the .txt files when you run your
> script a second time. Just make sure that the .txt is younger than the
> corresponding .doc by checking the file time.
>
> In short: use a caching strategy.
Thanks Peter. I'll surely check on that. Regards, Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Problem in Handling MySql Data.
Dear Group,
I am trying to write the following script to call around 0.3 million files from
a remote server.
It is generally working fine, but could work only upto 65 to 70 files. After
this, it is just
printing the file names and not processing anything. If anyone may kindly
suggest what I am
doing wrong?
import pymysql
import pymysql.cursors
import os
import win32com.client
from gensim.models import Word2Vec
import nltk
from nltk.corpus import stopwords
import pyPdf
from pyth.plugins.rtf15.reader import Rtf15Reader
from pyth.plugins.plaintext.writer import PlaintextWriter
import nltk
import zipfile, re
import time
#READING ONE DOC FILE FROM REMOTE LOCATION
def readfilesq9(n):
connection = pymysql.connect(host='xxx.xxx.x.xxx',
user='abcd',
passwd='pwd1',
db='rep_db',
charset='utf8mb4',
cursorclass=pymysql.cursors.DictCursor)
list1=[]
with connection.cursor() as cursor:
# Read a single record
sql = "SELECT candidateid,cnd.FirstName,
cnd.LastName,Concat('\\xxx.xxx.x.xxx\File\Cand_Res/',orgguid,'/',DATE_FORMAT(cnd.createddate,'%Y%m'),'/',candidateguid,'/',Resume)
as ResumePath from candidate cnd join mstorganization org on cnd.orgid =
org.OrgId where Resume <> '' and Resume is not null order by cnd.modifieddate
limit 10"
cursor.execute(sql)
result = cursor.fetchall()
#print result
#list1=[]
for i in result:
try:
#print i
item_1=i.items()
item_2=item_1[2][1]
print item_2
item_3=item_2.index("/")
file1=item_2[item_2:]
string1='xxx.xxx.x.xxx\\Resumes\\Cand_Res'
file1e=file1.encode('ascii', 'ignore')
urls=file1e.replace("/","\\")
file_full=string1+urls
time.sleep(1)
#osp="C:\\Python27"
os1=os.path.abspath(os.curdir)
osp2=os.path.join(os1,file_full)
print "Path1:",osp2
file_name1=osp2
print "Path:",file_name1
#IDENTIFICATION OF FILE KIND
#DOC CONVERSION
if ".doc" in file_name1:
#EXTRACTING ONLY .DOC FILES
if ".docx" not in file_name1:
#print "It is A Doc file$$:",file_name
try:
doc = win32com.client.GetObject(file_name1)
text = doc.Range().Text
text1=text.encode('ascii','ignore')
text_word=text1.split()
#print "The Text Word is:",text_word
#print "Text for Document File Is:",text1
list1.append(text_word)
#print "List for Doc File Is:",list3
#print "It is a Doc file"
except:
print "DOC ISSUE"
#EXTRACTING ONLY .DOCX FILES
elif ".docx" in file_name1:
#print "It is DOCX FILE:",file_name
docx1=zipfile.ZipFile(file_name1)
content =
docx1.read('word/document.xml').decode('utf-8')
cleaned =
re.sub('<(.|\n)*?>','',content).encode('ascii','ignore')
cleaned_word=cleaned.split()
#print "The Cleaned Document Is:",cleaned
list1.append(cleaned_word)
#print "List for DocX file Is:",list4
else:
print "NONE1"
else:
print "It is not a Doc file"
except:
print "OOPS1"
I am using Python2.7.6 on Enthought Canopy. It is not my default Python. My
default Python is in location,"C:\\Python27".
I am using MySql and Windows 7 Professional. Apology for any indentation error.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
IDLE Restoration
Dear Group, In many applications there is a facility to restore its previous sessions, especially if they close accidentally. Does IDLE have any such facility? If it is there, how may I use it? If someone may kindly suggest it. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Integrating Python Code with Django
Dear Group, I am trying to learn Django. My initial exercise seems fine. I want to create an API with REST on Django for an interactive Python code. REST framework on Django I am understanding more or less. I am looking for a simple example to start with. I am using Python 2.7+ on MS-Windows 7 Professional. If any one may kindly suggest. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Flask Post returning error
Dear Group,
I am trying to practice Flask and trying to correspond with it with through
requests.
I am being able to DELETE, GET. But as I am doing POST it is not posting the
data rather returning null.
I tried to search Flask and requests tutorials but did not get much.
I am newly practising Flask, and on Python2.7+ with Windows 7 Professional.
>>> var1=requests.get('http://127.0.0.1:5000/todos')
>>> var2=var2.text
>>> print var3
{
"todo1": {
"task": "build an API"
},
"todo2": {
"task": "How are you?"
},
"todo3": {
"task": "profit!"
}
}
>>> import json
>>> payload = {'key1': 'value1'}
>>> var4=requests.post('http://127.0.0.1:5000/todos', data=json.dumps(payload))
>>> var5=requests.get('http://127.0.0.1:5000/todos')
>>> var6=var5.text
>>> print var6
{
"todo1": {
"task": "build an API"
},
"todo3": {
"task": null
}
}
If anyone may kindly suggest what is the error I am doing.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Flask Post returning error
On Tuesday, May 19, 2015 at 10:34:35 AM UTC+5:30, Miki Tebeka wrote:
> > If anyone may kindly suggest what is the error I am doing.
> It's close to impossible to know without seeing the server side code.
Dear Sir,
I am trying to paste the code from:
from flask import Flask
from flask_restful import reqparse, abort, Api, Resource
app = Flask(__name__)
api = Api(app)
TODOS = {
'todo1': {'task': 'build an API'},
'todo2': {'task': 'How are you?'},
'todo3': {'task': 'profit!'},
}
def abort_if_todo_doesnt_exist(todo_id):
if todo_id not in TODOS:
abort(404, message="Todo {} doesn't exist".format(todo_id))
parser = reqparse.RequestParser()
parser.add_argument('task', type=str)
# Todo
# shows a single todo item and lets you delete a todo item
class Todo(Resource):
def get(self, todo_id):
abort_if_todo_doesnt_exist(todo_id)
return TODOS[todo_id]
def delete(self, todo_id):
abort_if_todo_doesnt_exist(todo_id)
del TODOS[todo_id]
return '', 204
def put(self, todo_id):
args = parser.parse_args()
task = {'task': args['task']}
TODOS[todo_id] = task
return task, 201
# TodoList
# shows a list of all todos, and lets you POST to add new tasks
class TodoList(Resource):
def get(self):
return TODOS
def post(self):
args = parser.parse_args()
todo_id = int(max(TODOS.keys()).lstrip('todo')) + 1
todo_id = 'todo%i' % todo_id
TODOS[todo_id] = {'task': args['task']}
return TODOS[todo_id], 201
##
## Actually setup the Api resource routing here
##
api.add_resource(TodoList, '/todos')
api.add_resource(Todo, '/todos/')
if __name__ == '__main__':
app.run(debug=True)
taken from:
http://flask.pocoo.org/docs/0.10/quickstart/
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
REST framework Editor in Python
Dear Group, I am trying to put one search engine interface in REST. To do this I am trying to learn Restframework and Django. One question occurred to me is, whether there is any Restframework editor which may do this job. Is there any? I was trying to find out https://pypi.python.org/pypi/restview -is it doing this? In that case, if any one may kindly share some examples or tutorial for it. Thanks in advance, Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Inverted Comma Search
Dear Group, I am trying to implement two searches, inverted comma search and search within brackets. I am trying to implement them in Whoosh, but not finding good tutorial or examples. If any one may kindly help me with. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Model Dumping Pickle
Dear Group,
If I use pickle to dump my model as follows,
>>> from gensim.models import Word2Vec
>>> from nltk.corpus import brown, movie_reviews, treebank
>>> b = Word2Vec(brown.sents())
>>> import pickle
>>> f = open('my_classifier5.pickle', 'wb')
>>> pickle.dump(b, f)
>>> f.close()
>>> f1= open('my_classifier5.pickle')
>>> classifier=pickle.load(f1)
>>> classifier.most_similar('money', topn=5)
[('pay', 0.6861867904663086), ('ready', 0.6255729794502258), ('try',
0.6118115186691284), ('go', 0.609034538269043), ('oppose', 0.6002943515777588)]
>>> f1.close()
Am I going fine? If any one may kindly suggest.
I am using Python 2.7 on MS-Windows 7 Professional.
Apology for any indentation error.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Error in or
Dear Group,
In the following script,
inp1=raw_input("PRINT YOUR INPUT:")
if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or
("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1):
if write this it is working fine, but if I write
if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1) or
("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or (''' "
''' in inp1):
the portion of (''' " ''' in inp1) is not working.
If any one of the esteemed members may kindly suggest the error I am making.
I am using Python2.7+ on Windows 7 Professional.
Apology for any indentation error.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Error in or
On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
> On Thu, Jun 11, 2015 at 9:40 AM,
> > if write this it is working fine, but if I write
> >
> > if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in inp1)
> > or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1) or
> > (''' " ''' in inp1):
> >
> > the portion of (''' " ''' in inp1) is not working.
>
> Not working how? I copy-pasted the line and it appears to work fine.
Dear Sir,
Thank you for your kind reply. Nice to know your reply, but I am trying to send
you my experiment, please see my results,
>>> def input1(n):
inp1=raw_input("PRINT YOUR QUERY:")
if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in
inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in inp1)
or (''' " ''' in inp1):
print "FINE"
>>> input1(1)
PRINT YOUR QUERY:"Java"
>>> input1(1)
PRINT YOUR QUERY:"Obama in London"
>>> input1(1)
PRINT YOUR QUERY:Obama AND Bush
FINE
>>> input1(1)
PRINT YOUR QUERY:Obama OR Bush
FINE
>>>
you may get better my problem.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Error in or
On Thursday, June 11, 2015 at 10:18:33 PM UTC+5:30, Ian wrote:
> On Thu, Jun 11, 2015 at 10:39 AM, wrote:
> > On Thursday, June 11, 2015 at 9:20:59 PM UTC+5:30, Ian wrote:
> >> On Thu, Jun 11, 2015 at 9:40 AM,
> >> > if write this it is working fine, but if I write
> >> >
> >> > if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in
> >> > inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in
> >> > inp1) or (''' " ''' in inp1):
> >> >
> >> > the portion of (''' " ''' in inp1) is not working.
> >>
> >> Not working how? I copy-pasted the line and it appears to work fine.
> >
> > Dear Sir,
> > Thank you for your kind reply. Nice to know your reply, but I am trying to
> > send you my experiment, please see my results,
> >
> >>>> def input1(n):
> > inp1=raw_input("PRINT YOUR QUERY:")
> > if ("AND" in inp1) or ("OR" in inp1) or ("NOT" in inp1) or (">" in
> > inp1) or ("&" in inp1) or ("MAYBE" in inp1) or ("(" in inp1) or ("*" in
> > inp1) or (''' " ''' in inp1):
> > print "FINE"
> >
> >
> >>>> input1(1)
> > PRINT YOUR QUERY:"Java"
> >>>> input1(1)
> > PRINT YOUR QUERY:"Obama in London"
> >>>> input1(1)
> > PRINT YOUR QUERY:Obama AND Bush
> > FINE
> >>>> input1(1)
> > PRINT YOUR QUERY:Obama OR Bush
> > FINE
> >>>>
> >
> > you may get better my problem.
>
> The substring that you're looking for has spaces around the " symbol.
> The example inputs that you gave don't have spaces around the "
> symbols, so they don't contain the substring. The triple quotes are
> also unnecessary, though harmless -- it's not a multiline string, and
> there are no ' symbols to escape in the string. Try replacing the
> substring with just this: '"'.
Dear Sir,
Thank you. It seems working.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
How may I Integrate Python Code with REST
Dear Group, I wrote a Python code. In the code there are two modules where we may insert data from outside. They are updating some training module and updating index. As a standalone code this is working fine. I need to port this code to REST. I tried to learn Flask. My Practice for Flask is okay. I can put,get,delete. But how may I proceed I am not getting much idea. I bit new in REST. If any one of the esteemed members may kindly provide an idea how may I proceed? Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: How may I Integrate Python Code with REST
On Saturday, June 13, 2015 at 2:17:43 AM UTC+5:30, Laura Creighton wrote:
> In a message of Fri, 12 Jun 2015 10:52:19 -0700, w
> rites:
> >Dear Group,
> >
> >I wrote a Python code. In the code there are two modules where we may insert
> >data from outside. They are updating some training module and updating
> >index. As a standalone code this is working fine.
> >
> >I need to port this code to REST. I tried to learn Flask. My Practice for
> >Flask is okay. I can put,get,delete.
> >
> >But how may I proceed I am not getting much idea. I bit new in REST.
> >If any one of the esteemed members may kindly provide an idea how may I
> >proceed?
> >
> >Regards,
> >Subhabrata Banerjee.
>
> All you need now is post. So it looks as if you have all the bits you
> need, but you don't know how to use them to design an API.
>
> See if this helps.
> http://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask
>
> If not, you are probably at the stage of posting code here.
> Here is my code that doesn't work.
> Here is what happens when I run it.
> This is what I wish it would do instead.
>
> Right now we don't understand what it is that you don't understand, alas.
> Code makes the problem obvious.
>
> Laura
Hi,
Thank you for your post. Yes I can PUT the data in JSON format but how to
interact with the code I am thinking on that. My script snippet of Flask is as
follows,
>>> x3=requests.put('http://127.0.0.1:5000/todos/todo1', data={'task': 'We are
>>> trying to build API. API seems okay.'})
>>> x4=requests.get('http://127.0.0.1:5000/todos')
>>> x5=x4.text
>>> print x5
{
"todo1": {
"task": "We are trying to build API. API seems okay."
},
"todo2": {
"task": "Change my brakepads"
},
"todo3": {
"task": "Life is okay"
}
}
Now, as I understand it I have to work out something around this PUT.
As per my guess,
1. I should work around this put if takes data from file.
2. The data I would get thus, I have to convert this JSON data (by import json
or so), into text or the format my main code understands as input.
Am I thinking fine. If not please suggest.
There is an interesting error occurs almost every other day port 5000
in
requests.get('http://127.0.0.1:5000/todos') gives error everyother day.
I have stopped firewall, consulted senior administrators of system group but no
error seems there. It works suddenly and does not work suddenly,
if you suggest how to fix this issue.
I am using Python2.7+ on MS-Windows 7 Professional. I am using Microsoft
Security Essentials as AntiVirus.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Creating .exe file in Python
Dear Group, I am trying to learn how to create .exe file for Python. I tried to work around http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went nice. But if I try to make exe for larger programs with methods and classes I am getting error. If any one of the esteemed members may kindly suggest how to work out. I am using Python2.7+ on Windows 7 Professional. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Monday, June 15, 2015 at 6:32:33 PM UTC+5:30, Laura Creighton wrote:
> In a message of Mon, 15 Jun 2015 04:42:09 -0700, w
> rites:
> >Dear Group,
> >
> >I am trying to learn how to create .exe file for Python. I tried to work
> >around
> >http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went
> >nice.
> >But if I try to make exe for larger programs with methods and classes I am
> >getting error.
> >
> >If any one of the esteemed members may kindly suggest how to work out.
> >I am using Python2.7+ on Windows 7 Professional.
> >
> >Regards,
> >Subhabrata Banerjee.
>
> 1. Post the error.
>
> 2. I have always had better luck with PyInstaller than with py2exe
>https://github.com/pyinstaller/pyinstaller/wiki
>
> Laura
Dear Group,
I wrote a script as NLQ3. py
the code is written as,
import nltk
import itertools
def nlq3(n):
inp=raw_input("Print Your Query:")
tag=nltk.pos_tag(nltk.wordpunct_tokenize(inp))
print "The Tagged Value Is:",tag
noun=[word[0] for word in tag if 'NN' in word[1]]
#print noun
#COMBINATION OF ALL ELEMENTS
for i in xrange(1,len(noun)+1):
comb= list(itertools.combinations(noun,i))
for i,v in enumerate(comb):
#print v
v1=list(v)
print v1
I tried to call it as,
C:\Tutorial>python hello.py
...
as
C:\Python27>python NLQ3.py
C:\Python27>
But I am not getting any output.
Next I tried to create setup.py as,
from distutils.core import setup
import py2exe
setup(console=['NLQ3.py'])
and trying to work out as,
C:\Python27>python setup.py install
running install
running build
running install_egg_info
Removing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info
Writing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info
C:\Python27>
Now,
as I am giving
C:\Python27>python setup.py py2exe
it is giving me the following result,
running py2exe
*** searching for required modules ***
*** parsing results ***
creating python loader for extension 'scipy.optimize.minpack2' (C:\Python27\lib\
site-packages\scipy\optimize\minpack2.pyd -> scipy.optimize.minpack2.pyd)
creating python loader for extension 'numpy.core.umath' (C:\Python27\lib\site-pa
ckages\numpy\core\umath.pyd -> numpy.core.umath.pyd)
creating python loader for extension '_elementtree' (C:\Python27\DLLs\_elementtr
ee.pyd -> _elementtree.pyd)
creating python loader for extension 'matplotlib._path' (C:\Python27\lib\site-pa
ckages\matplotlib\_path.pyd -> matplotlib._path.pyd)
creating python loader for extension 'numpy.fft.fftpack_lite' (C:\Python27\lib\s
ite-packages\numpy\fft\fftpack_lite.pyd -> numpy.fft.fftpack_lite.pyd)
creating python loader for extension 'numpy.lib._compiled_base' (C:\Python27\lib
\site-packages\numpy\lib\_compiled_base.pyd -> numpy.lib._compiled_base.pyd)
creating python loader for extension 'scipy.optimize._minpack' (C:\Python27\lib\
site-packages\scipy\optimize\_minpack.pyd -> scipy.optimize._minpack.pyd)
creating python loader for extension '_ctypes' (C:\Python27\DLLs\_ctypes.pyd ->
_ctypes.pyd)
creating python loader for extension 'scipy.sparse.linalg.isolve._iterative' (C:
\Python27\lib\site-packages\scipy\sparse\linalg\isolve\_iterative.pyd -> scipy.s
parse.linalg.isolve._iterative.pyd)
creating python loader for extension 'sklearn.linear_model.sgd_fast' (C:\Python2
7\lib\site-packages\sklearn\linear_model\sgd_fast.pyd -> sklearn.linear_model.sg
d_fast.pyd)
creating python loader for extension 'scipy.stats._rank' (C:\Python27\lib\site-p
ackages\scipy\stats\_rank.pyd -> scipy.stats._rank.pyd)
creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> se
lect.pyd)
creating python loader for extension 'scipy.sparse.csgraph._reordering' (C:\Pyth
on27\lib\site-packages\scipy\sparse\csgraph\_reordering.pyd -> scipy.sparse.csgr
aph._reordering.pyd)
creating python loader for extension 'unicodedata' (C:\Python27\DLLs\unicodedata
.pyd -> unicodedata.pyd)
creating python loader for extension 'scipy.special.specfun' (C:\Python27\lib\si
te-packages\scipy\special\specfun.pyd -> scipy.special.specfun.pyd)
creating python loader for extension 'scipy.spatial.qhull' (C:\Python27\lib\site
-packages\scipy\spatial\qhull.pyd -> scipy.spatial.qhull.pyd)
creating python loader for extension 'scipy.interpolate._ppoly' (C:\Python27\lib
\site-packages\scipy\interpolate\_ppoly.pyd -> scipy.interpolate._ppoly.pyd)
creating python loader for extension 'scipy.sparse.csgraph._tools' (C:\Python27\
lib\site-packages\scipy\sparse\csgraph\_tools.pyd -> scipy.sparse.csgraph._tools
.pyd)
creating pyt
Re: Creating .exe file in Python
On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, [email protected] wrote: > Dear Group, > > I am trying to learn how to create .exe file for Python. I tried to work > around > http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went > nice. > But if I try to make exe for larger programs with methods and classes I am > getting error. > > If any one of the esteemed members may kindly suggest how to work out. > I am using Python2.7+ on Windows 7 Professional. > > Regards, > Subhabrata Banerjee. I am also experimenting around Pyinstaller, cx_Freeze and Inno Studio. But not finding ample examples and manuals. Regards, Subhabrata. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Monday, June 15, 2015 at 8:02:21 PM UTC+5:30, Thierry Chappuis wrote: > Hi, > > The question is why to you want to create an exe from your > python project? > > Setuptools is capable to create small .exe launchers in the > Scripts dir of your python install. These launchers start a python script > and use the python interpreter registered on your platform. That's pretty > light and that's my prefered solution. > > If installing the Python interpreter is an issue for the end > user, we can make the installer do it for him. Installer programs like Inno > Setup let you do it quite easily. > > Kind regards > > Thierry > > > > On lun., juin 15, 2015 at > 4:10 PM, > wrote: > > > On Monday, June 15, 2015 at > 5:12:24 PM UTC+5:30, [email protected] wrote: > > > > Dear Group, > > > > > > > > I am trying to learn how to create .exe file for Python. I tried to > work around > > > > http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program > went nice. > > > > But if I try to make exe for larger programs with methods and classes > I am getting error. > > > > > > > > If any one of the esteemed members may kindly suggest how to work out. > > > > > I am using Python2.7+ on Windows 7 Professional. > > > > > > > > Regards, > > > > Subhabrata Banerjee. > > > > > > I am also experimenting around Pyinstaller, cx_Freeze and Inno Studio. But > not finding ample examples and manuals. > > > Regards, > > > Subhabrata. > > > -- > > > https://mail.python.org/mailman/listinfo/python-list Thank you for your kind reply. I have downloaded it, but no good tutorial. If you may send any. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, [email protected] wrote: > Dear Group, > > I am trying to learn how to create .exe file for Python. I tried to work > around > http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went > nice. > But if I try to make exe for larger programs with methods and classes I am > getting error. > > If any one of the esteemed members may kindly suggest how to work out. > I am using Python2.7+ on Windows 7 Professional. > > Regards, > Subhabrata Banerjee. Dear Madam, Thanks. Most of it is working except the last portion as I am giving python setup.py py2exe Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Users\Admin>cd\ C:\>cd Python27 C:\Python27>python NLQ3.py Print Your Query:Java The Tagged Value Is: [('Java', 'NNP')] ['Java'] C:\Python27>python NLQ3.py Print Your Query:Obama is the president of USA The Tagged Value Is: [('Obama', 'NNP'), ('is', 'VBZ'), ('the', 'DT'), ('presiden t', 'NN'), ('of', 'IN'), ('USA', 'NNP')] ['Obama'] ['president'] ['USA'] ['Obama', 'president'] ['Obama', 'USA'] ['president', 'USA'] ['Obama', 'president', 'USA'] C:\Python27>python setup.py install running install running build running install_egg_info Removing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info Writing C:\Python27\Lib\site-packages\UNKNOWN-0.0.0-py2.7.egg-info C:\Python27>python setup.py py2exe running py2exe *** searching for required modules *** *** parsing results *** creating python loader for extension 'scipy.optimize.minpack2' (C:\Python27\lib\ site-packages\scipy\optimize\minpack2.pyd -> scipy.optimize.minpack2.pyd) creating python loader for extension 'numpy.core.umath' (C:\Python27\lib\site-pa ckages\numpy\core\umath.pyd -> numpy.core.umath.pyd) creating python loader for extension '_elementtree' (C:\Python27\DLLs\_elementtr ee.pyd -> _elementtree.pyd) creating python loader for extension 'matplotlib._path' (C:\Python27\lib\site-pa ckages\matplotlib\_path.pyd -> matplotlib._path.pyd) creating python loader for extension 'numpy.fft.fftpack_lite' (C:\Python27\lib\s ite-packages\numpy\fft\fftpack_lite.pyd -> numpy.fft.fftpack_lite.pyd) creating python loader for extension 'numpy.lib._compiled_base' (C:\Python27\lib \site-packages\numpy\lib\_compiled_base.pyd -> numpy.lib._compiled_base.pyd) creating python loader for extension 'scipy.optimize._minpack' (C:\Python27\lib\ site-packages\scipy\optimize\_minpack.pyd -> scipy.optimize._minpack.pyd) creating python loader for extension '_ctypes' (C:\Python27\DLLs\_ctypes.pyd -> _ctypes.pyd) creating python loader for extension 'scipy.sparse.linalg.isolve._iterative' (C: \Python27\lib\site-packages\scipy\sparse\linalg\isolve\_iterative.pyd -> scipy.s parse.linalg.isolve._iterative.pyd) creating python loader for extension 'sklearn.linear_model.sgd_fast' (C:\Python2 7\lib\site-packages\sklearn\linear_model\sgd_fast.pyd -> sklearn.linear_model.sg d_fast.pyd) creating python loader for extension 'scipy.stats._rank' (C:\Python27\lib\site-p ackages\scipy\stats\_rank.pyd -> scipy.stats._rank.pyd) creating python loader for extension 'select' (C:\Python27\DLLs\select.pyd -> se lect.pyd) creating python loader for extension 'scipy.sparse.csgraph._reordering' (C:\Pyth on27\lib\site-packages\scipy\sparse\csgraph\_reordering.pyd -> scipy.sparse.csgr aph._reordering.pyd) creating python loader for extension 'unicodedata' (C:\Python27\DLLs\unicodedata .pyd -> unicodedata.pyd) creating python loader for extension 'scipy.special.specfun' (C:\Python27\lib\si te-packages\scipy\special\specfun.pyd -> scipy.special.specfun.pyd) creating python loader for extension 'scipy.spatial.qhull' (C:\Python27\lib\site -packages\scipy\spatial\qhull.pyd -> scipy.spatial.qhull.pyd) creating python loader for extension 'scipy.interpolate._ppoly' (C:\Python27\lib \site-packages\scipy\interpolate\_ppoly.pyd -> scipy.interpolate._ppoly.pyd) creating python loader for extension 'scipy.sparse.csgraph._tools' (C:\Python27\ lib\site-packages\scipy\sparse\csgraph\_tools.pyd -> scipy.sparse.csgraph._tools .pyd) creating python loader for extension 'scipy.interpolate.dfitpack' (C:\Python27\l ib\site-packages\scipy\interpolate\dfitpack.pyd -> scipy.interpolate.dfitpack.py d) creating python loader for extension 'scipy.linalg._fblas' (C:\Python27\lib\site -packages\scipy\linalg\_fbl
Re: Creating .exe file in Python
On Monday, June 15, 2015 at 9:59:33 PM UTC+5:30, Laura Creighton wrote: > I don't have a windows system, so my knowledge of such things is > minimal. But looks like this person had the same problem you have, > and got some suggestions on how to fix it. > > http://stackoverflow.com/questions/12127869/error-msvcp90-dll-no-such-file-or-directory-even-though-microsoft-visual-c > > But your code is working fine now? There is no point in packaging > something that doesn't run. > > Laura Hi, Thank you for your help. Yes now the file is giving output as I am calling it in command prompt. I had downloaded Microsoft Visual Studio 2008 Redistributable. I have MS VC 10.0 installed so my corresponding CRT file is 100 and not 90. I am checking this and working out. Meanwhile got another post http://stackoverflow.com/questions/323424/py2exe-fails-to-generate-an-executable and pasted libiomp5md.dll from numpy now it is giving NLQ3.exe in dist and generating few errors in a corresponding log file. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Monday, June 15, 2015 at 9:59:33 PM UTC+5:30, Laura Creighton wrote: > I don't have a windows system, so my knowledge of such things is > minimal. But looks like this person had the same problem you have, > and got some suggestions on how to fix it. > > http://stackoverflow.com/questions/12127869/error-msvcp90-dll-no-such-file-or-directory-even-though-microsoft-visual-c > > But your code is working fine now? There is no point in packaging > something that doesn't run. > > Laura I have mostly solved the problem. But there are two issues making me slightly confusing: i) In a bigger code I am calling scipy and after building .exe as I am calling \dist\...exe it is giving ImportError: No module named _ufuncs_cxx I have checked the resolution http://stackoverflow.com/questions/20169728/exe-created-with-py2exe-doesnt-work-and-returns-logfile-with-errors but it is not giving much help. ii) In a class how may I include if __name__ == "__main__": with multiple methods? But I think this is easy question there should be lot of web help. If anyone may kindly suggest. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Tuesday, June 16, 2015 at 8:35:39 PM UTC+5:30, Laura Creighton wrote: > In a message of Tue, 16 Jun 2015 06:56:12 -0700, writes: > >ii) In a class how may I include if __name__ == "__main__": with multiple > >methods? But I think this is easy question there should be lot of web help. > > > >If anyone may kindly suggest. > > > >Regards, > >Subhabrata Banerjee. > > There is something wrong in the way you are thinking about this. > You don't _want_ to stick if __name__ = "__main__": > into every class you write. > > See if reading this helps. > http://effbot.org/pyfaq/tutor-what-is-if-name-main-for.htm > > Laura Hi, Thanks. The scipy issue seems solved. But this silly issue is giving so much of time. I am checking. Please see a sample code, import sys sys.stderr = sys.stdout class Colors: def Blue(self): self.var="This is Blue" print self.var def Red(self): print self.var if __name__ == "__main__": Colors().Blue() #THIS IS FINE Colors().Red() #NOT FINE Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Tuesday, June 16, 2015 at 9:33:58 PM UTC+5:30, Chris Angelico wrote: > On Wed, Jun 17, 2015 at 1:17 AM, wrote: > > Thanks. The scipy issue seems solved. But this silly issue is giving so > > much of time. I am checking. Please see a sample code, > > > > import sys > > sys.stderr = sys.stdout > > class Colors: > > def Blue(self): > > self.var="This is Blue" > > print self.var > > def Red(self): > > print self.var > > > > > > > > if __name__ == "__main__": > > Colors().Blue() #THIS IS FINE > > Colors().Red() #NOT FINE > > You're still not saying what's going on. Did you try this code as a > simple Python script first, before trying to bundle it up into an .exe > file? > > Fortunately, my primary crystal ball is active, and I believe what's > going on is that you expect Blue() to set something and then Red() to > see it. However, you're calling those methods on two different > throw-away objects, so they have separate state. What you expect to > happen, I honestly have no idea. (Also, why are you fiddling with > sys.stderr? You don't then appear to be using it, unless you have an > issue with exceptions getting printed to the other stream.) > > ChrisA Thank you for your reply. I am trying to experimenting over small ones before going to actual code. Your error interpretations are right. I could work out a small solution please check if it is going fine. It is giving me result. if __name__ == "__main__": c1=Colors() c2=c1.Blue() c3=c1.Red() Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Tuesday, June 16, 2015 at 9:33:58 PM UTC+5:30, Chris Angelico wrote: > On Wed, Jun 17, 2015 at 1:17 AM, wrote: > > Thanks. The scipy issue seems solved. But this silly issue is giving so > > much of time. I am checking. Please see a sample code, > > > > import sys > > sys.stderr = sys.stdout > > class Colors: > > def Blue(self): > > self.var="This is Blue" > > print self.var > > def Red(self): > > print self.var > > > > > > > > if __name__ == "__main__": > > Colors().Blue() #THIS IS FINE > > Colors().Red() #NOT FINE > > You're still not saying what's going on. Did you try this code as a > simple Python script first, before trying to bundle it up into an .exe > file? > > Fortunately, my primary crystal ball is active, and I believe what's > going on is that you expect Blue() to set something and then Red() to > see it. However, you're calling those methods on two different > throw-away objects, so they have separate state. What you expect to > happen, I honestly have no idea. (Also, why are you fiddling with > sys.stderr? You don't then appear to be using it, unless you have an > issue with exceptions getting printed to the other stream.) > > ChrisA Dear Group, Thank you all. It seems going fine now. I have one additional question if I run the .exe files created in Non Python Windows environment. Linux has Python builtin but in Non Python environment how may I run it? Is there any set of prequisites I have to follow. I am not finding much web help, if any one may kindly suggest. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Wednesday, June 17, 2015 at 6:50:48 PM UTC+5:30, Chris Angelico wrote: > On Wed, Jun 17, 2015 at 11:10 PM, wrote: > > Thank you all. It seems going fine now. I have one additional question if I > > run the .exe files created in Non Python Windows environment. Linux has > > Python builtin but in Non Python environment how may I run it? Is there any > > set of prequisites I have to follow. I am not finding much web help, if any > > one may kindly suggest. > > > > There have been some proposals to make an easy way to produce a single > package that has a Windows executable header, but can be easily > unpacked and run using a system-provided Linux or Mac OS Python. > However, I don't think any have been deployed yet. So the simple > answer is: You can't do what you're trying to do. Instead, take a step > back, and look at just getting your Python program to run on all > platforms... and that's easy, just distribute the .py files. Much MUCH > easier, more reliable, and simpler. > > ChrisA Dear Sir, Thank you for your kind and prompt answer. I was about to explore another package. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Wednesday, June 17, 2015 at 7:25:39 PM UTC+5:30, Laura Creighton wrote: > In a message of Wed, 17 Jun 2015 06:10:45 -0700, w > rites: > > >Dear Group, > > > >Thank you all. It seems going fine now. I have one additional question if I > >run the .exe files created in Non Python Windows environment. Linux has > >Python builtin but in Non Python environment how may I run it? Is there any > >set of prequisites I have to follow. I am not finding much web help, if any > >one may kindly suggest. > > > >Regards, > >Subhabrata Banerjee. > > If you use py2exe or PyInstaller (or whatever it is you used) to make > your exe, then all of this is handled for you. Hand the windows users > the exe and they are good to go. But the last time you posted here, > your py2exe wasn't working well. You were getting Import Errors. > If you make a broken exe, well, it will be broken for the windows > users as well. > > Laura Thanks. I will check. I am calling the .exe from C:\Python27\dist... would it run in non Python Windows Environment? Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, [email protected] wrote: > Dear Group, > > I am trying to learn how to create .exe file for Python. I tried to work > around > http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program went > nice. > But if I try to make exe for larger programs with methods and classes I am > getting error. > > If any one of the esteemed members may kindly suggest how to work out. > I am using Python2.7+ on Windows 7 Professional. > > Regards, > Subhabrata Banerjee. But if I am moving the file from Python environment and to another folder in C: drive it is not running, it is giving me following error messages, Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\tutorial>hello.exe LoadLibrary(pythondll) failedThe specified module could not be found. C:\tutorial\PYTHON27.DLL C:\tutorial> Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Wednesday, June 17, 2015 at 7:47:59 PM UTC+5:30, [email protected] wrote: > On Wed, Jun 17, 2015, at 09:33, hamilton wrote: > > However, the python source can be read by anyone. > > > > As a .exe, the source can not be read. > > > > Just because the interpreter is open source, > > does not mean my application should be. > > Being readable isn't the same thing as being open source. If someone > steals your application, you can sue them. Guido can create another Python. I know my limits. So I never steal or copy unnecessarily I learn. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Wednesday, June 17, 2015 at 8:52:16 PM UTC+5:30, Laura Creighton wrote: > In a message of Wed, 17 Jun 2015 07:16:33 -0700, w > rites: > >On Monday, June 15, 2015 at 5:12:24 PM UTC+5:30, wrote: > >> Dear Group, > >> > >> I am trying to learn how to create .exe file for Python. I tried to work > >> around > >> http://www.py2exe.org/index.cgi/Tutorial of Py2exe. The sample program > >> went nice. > >> But if I try to make exe for larger programs with methods and classes I am > >> getting error. > >> > >> If any one of the esteemed members may kindly suggest how to work out. > >> I am using Python2.7+ on Windows 7 Professional. > >> > >> Regards, > >> Subhabrata Banerjee. > > > >But if I am moving the file from Python environment and to another folder in > >C: drive it is not running, it is giving me following error messages, > >Microsoft Windows [Version 6.1.7601] > >Copyright (c) 2009 Microsoft Corporation. All rights reserved. > > > >C:\tutorial>hello.exe > >LoadLibrary(pythondll) failedThe specified module could not be found. > >C:\tutorial\PYTHON27.DLL > >C:\tutorial> > > > >Regards, > >Subhabrata Banerjee. > > You have to distribute the DLL as well. > But at this point you need somebody who knows more about packaging > for windows than I do. It's not something I do often, or well. > > Laura Hi, My need is done. But I can learn. I saw few .pyd files in dist folder. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Creating .exe file in Python
On Wednesday, June 17, 2015 at 9:09:32 PM UTC+5:30, Steven D'Aprano wrote: > On Wed, 17 Jun 2015 11:52 pm, Chris Angelico wrote: > > > If you truly want to protect your code from prying eyes, therefore, > > there's only one way to do it: host it on a server, and let people > > access the server without seeing the code. > > Stop giving people ideas. > > > > -- > Steven Why sir? Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Combing Search Engine with REST
Dear Group, I am trying to make a search engine. I used Whoosh to do it. I want to add documents to it. This is going fine. Now, I want to add documents in the index with REST framework. I could learn Flask well. My task is to use Flask to add documents (by using put/post) to index. I am slightly confused how may I do it. If any one of esteemed members of the group may suggest. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
File Upload in Restful Flask
Dear Group, I am trying to learn Rest framework through Restful Flask. My initial exercises went fine with https://flask-restful.readthedocs.org/en/0.3.3/quickstart.html Now I want to upload file through Restful Flask. I tried to check the web for reference. I got these urls, (i) http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file (ii) http://stackoverflow.com/questions/28982974/flask-restful-upload-image (iii) http://blog.luisrei.com/articles/flaskrest.html But the question I am stuck with what are the things I have to change in the example of quickstart tutorial so that I may be able to upload file. Or if any one may kindly suggest with a small example. If any one of the esteemed members may kindly suggest. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: File Upload in Restful Flask
On Monday, July 20, 2015 at 4:40:09 PM UTC+5:30, Simmo wrote:
> On 20/07/2015 11:13, wrote:
> > Dear Group,
> >
> > I am trying to learn Rest framework through Restful Flask.
> > My initial exercises went fine with
> > https://flask-restful.readthedocs.org/en/0.3.3/quickstart.html
> >
> > Now I want to upload file through Restful Flask. I tried to check the web
> > for reference.
> > I got these urls,
> > (i)
> > http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
> > (ii) http://stackoverflow.com/questions/28982974/flask-restful-upload-image
> > (iii) http://blog.luisrei.com/articles/flaskrest.html
> >
> > But the question I am stuck with what are the things I have to change in
> > the example of quickstart tutorial so that I may be able to upload file. Or
> > if any one may kindly suggest with a small example.
> >
> > If any one of the esteemed members may kindly suggest.
> >
> > Regards,
> > Subhabrata Banerjee.
> >
>
> I'm no expert on Python or REST but the example
>
> >>> url = 'http://httpbin.org/post'
> >>> files = {'file': open('report.xls', 'rb')}
>
> >>> r = requests.post(url, files=files)
> >>> r.text
> ...
>
> seems quite straightforward so I would suggest substituting your URL for
> 'http://httpbin.org' and your file name (possibly with full pathname)
> for 'report.xls'.
>
> Give it a try and report back...
>
> Steve S
Dear Sir,
Thanks. I could change the quickstart api.py slightly. I ran your suggestion
on it. Some result seems coming but I may have to improve some portion, I am
not getting. Please see the same.
>>> import requests
>>> url='http://127.0.0.1:5000/toworks/post'
>>> files = {'file': open('C:\Python27\NEWS.txt', 'rb')}
>>> r = requests.post(url, files=files)
>>> r.text
u'{\n"message": "Method Not Allowed", \n"status": 405\n}\n'
>>>
Regards,
Subhabrata Banerji
--
https://mail.python.org/mailman/listinfo/python-list
Re: File Upload in Restful Flask
On Monday, July 20, 2015 at 6:39:29 PM UTC+5:30, Simmo wrote:
> On 20/07/2015 12:57, wrote:
> > On Monday, July 20, 2015 at 4:40:09 PM UTC+5:30, Simmo wrote:
> >> On 20/07/2015 11:13, wrote:
> >>> Dear Group,
> >>>
> >>> I am trying to learn Rest framework through Restful Flask.
> >>> My initial exercises went fine with
> >>> https://flask-restful.readthedocs.org/en/0.3.3/quickstart.html
> >>>
> >>> Now I want to upload file through Restful Flask. I tried to check the web
> >>> for reference.
> >>> I got these urls,
> >>> (i)
> >>> http://docs.python-requests.org/en/latest/user/quickstart/#post-a-multipart-encoded-file
> >>> (ii)
> >>> http://stackoverflow.com/questions/28982974/flask-restful-upload-image
> >>> (iii) http://blog.luisrei.com/articles/flaskrest.html
> >>>
> >>> But the question I am stuck with what are the things I have to change in
> >>> the example of quickstart tutorial so that I may be able to upload file.
> >>> Or if any one may kindly suggest with a small example.
> >>>
> >>> If any one of the esteemed members may kindly suggest.
> >>>
> >>> Regards,
> >>> Subhabrata Banerjee.
> >>>
> >>
> >> I'm no expert on Python or REST but the example
> >>
> >>>>> url = 'http://httpbin.org/post'
> >>>>> files = {'file': open('report.xls', 'rb')}
> >>
> >>>>> r = requests.post(url, files=files)
> >>>>> r.text
> >> ...
> >>
> >> seems quite straightforward so I would suggest substituting your URL for
> >> 'http://httpbin.org' and your file name (possibly with full pathname)
> >> for 'report.xls'.
> >>
> >> Give it a try and report back...
> >>
> >> Steve S
> >
> > Dear Sir,
> >
> > Thanks. I could change the quickstart api.py slightly. I ran your suggestion
> > on it. Some result seems coming but I may have to improve some portion, I
> > am not getting. Please see the same.
> >
> >>>> import requests
> >>>> url='http://127.0.0.1:5000/toworks/post'
> >>>> files = {'file': open('C:\Python27\NEWS.txt', 'rb')}
> >>>> r = requests.post(url, files=files)
> >>>> r.text
> > u'{\n"message": "Method Not Allowed", \n"status": 405\n}\n'
> >>>>
> >
> > Regards,
> > Subhabrata Banerji
> >
>
> OK, so that message is telling you that whatever server is sitting
> behind 127.0.0.1 is not allowing you (your code) to POST to it. There
> are many reasons why this could be happening. Here are a couple for you
> to investigate...
>
> - port 5000 is not not 'open' for POSTs
> - your code may not have permission to POST to the server
>
> It would help if you could tell us what OS you are using (Windows or
> Linux or ...) and what server is sitting behind 127.0.0.1.
>
> I'n not going to be around for the next 24hrs but I'm sure someone else
> on the list will have some suggestions for you...
>
> Happy bug hunting
>
> Steve
Dear Sir,
Thanks. I am on MS-Windows 7 and I use mostly Firefox. I am checking other
issues.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Search in Flask Restful
Dear Group,
I am trying to build one REST framework using Restful Flask.
To put or get I am trying to use the requests module, as
given in the following lines.
>>> var2=requests.put('http://127.0.0.1:5000/todos/todo1', data={'task': 'It is
>>> my challenge'})
>>> var3=requests.get('http://127.0.0.1:5000/todos/todo1')
Now I like to search plain as well as Boolean over this Rest.
If I could understand the problem fine, the exercises are given
in the following URL.
http://flask-restless.readthedocs.org/en/latest/searchformat.html#examples
But I am looking for examples with requests. I searched for help with requests
in http://docs.python-requests.org/en/latest/, it did not help much.
If anyone of the esteemed members may kindly suggest.
I am using Python2.7+ on Windows 7. Apology for any indentation error.
Regards,
Subhabrata Banerjee
--
https://mail.python.org/mailman/listinfo/python-list
How may I learn Python Web Frameworks
Dear Group, I am slightly new in Python Web Frameworks. I could learn bit of Django, Flask and Bottle. But I am looking for a good web based tutorial like Python or NLTK. Somehow, I did not find documentations for web frameworks are very good, one has to do lot of experiments even to learn basic things. I am looking for a good book like Dive into Python or some good web based tutorials. I tried to search but unfortunately could not find. I am using Python2.7+ on Windows 7. If any one of the members may kindly suggest. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Logical Query in Python
Dear Group, I am trying to query JSON with Logical operators. I tried to experiment lot with it, but could not do much. I came many times pretty close but missed it almost. I tried to experiment with json, jsonquery, jsonschema, jsonpipe, objectpath, requests. I got a good example from http://www-01.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.json/src/tpc/db2z_jsonlogicaloperators.dita But I was looking for one or two worked out examples to start with. I am using Python2.7+ on Windows 7 with IDLE as GUI. I am trying and if anybody of the esteemed members may kindly help me with. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Logical Query JSON
Dear Group, I am trying to query JSON with Logical operators. I tried to experiment lot with it, but could not do much. I came many times pretty close but missed it almost. I tried to experiment with json, jsonquery, jsonschema, jsonpipe, objectpath, requests. I got a good example from http://www-01.ibm.com/support/knowledgecenter/SSEPEK_11.0.0/com.ibm.db2z11.doc.json/src/tpc/db2z_jsonlogicaloperators.dita But I was looking for one or two worked out examples to start with. I am using Python2.7+ on Windows 7 with IDLE as GUI. I am trying and if anybody of the esteemed members may kindly help me with. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Re: Logical Query JSON
On Thursday, July 30, 2015 at 9:20:35 PM UTC+5:30, Denis McMahon wrote:
> On Thu, 30 Jul 2015 06:32:01 -0700, subhabrata.banerji wrote:
>
> > I am trying to query JSON with Logical operators.
>
> Your post was an excellent example of asking for help without explaining
> what your problem was at all.
>
> Please:
>
> - show an example of what you tried;
>
> - give the results you expected;
>
> - show the results you actually got.
>
> COPY and PASTE the code and results, do not re-type them, or summarise
> them.
>
> I found the examples quite easy to follow to create json queries,
> although as I don't have a db2 etc setup here iI'm unale to try feeding
> the resulting json query into a database to see what comes out.
>
> --
> Denis McMahon
Dear Sir,
I am trying to quote some of my exercises below, and my objective.
(1) Exercise with objectpath:
>>> from objectpath import *
>>> tree=Tree({"a":1})
>>> tree.execute("$.a")
1
>>> $
{
"a":1,
"b":{
"c":[1,2,3]
}
}
SyntaxError: invalid syntax
>>> x1={"a":1,"b":{"c":[1,2,3]}}
>>> x1.b
Traceback (most recent call last):
File "", line 1, in
x1.b
AttributeError: 'dict' object has no attribute 'b'
>>> x1."b"
SyntaxError: invalid syntax
(2) Exercise from IBM Example:
>>> x1={"or":[{"age":4},{"name":"Joe"}]}
>>> x2=x1
>>> print x2
{'or': [{'age': 4}, {'name': 'Joe'}]}
>>> x1['age']
Traceback (most recent call last):
File "", line 1, in
x1['age']
KeyError: 'age'
>>> x1['or']
[{'age': 4}, {'name': 'Joe'}]
>>> x1['or']['age']
Traceback (most recent call last):
File "", line 1, in
x1['or']['age']
TypeError: list indices must be integers, not str
>>> x1['or'][0]
{'age': 4}
>>> x1['or'][1]
{'name': 'Joe'}
My expectation is:
If I do AND, NOT, OR with two or more JSON values like
{"age":4}, {"name":"Joe"}, ...etc. then I should get recirprocal
results.
Considering each one as Python variable and applying logical Python
operation helps, but I am looking a smarter solution.
Apology for indentation error.
Regards,
Subhabrata Banerjee.
--
https://mail.python.org/mailman/listinfo/python-list
Re: Logical Query in Python
On Thursday, July 30, 2015 at 8:35:08 PM UTC+5:30, Steven D'Aprano wrote: > On Thu, 30 Jul 2015 11:28 pm, wrote: > > > Dear Group, > > > > I am trying to query JSON with Logical operators. > > What does that mean? > > > I tried to experiment lot with it, but could not do much. > > I came many times pretty close but missed it almost. > > Please: > > - show an example of what you tried; > > - give the results you expected; > > - show the results you actually got. > > COPY and PASTE the code and results, do not re-type them, or summarise them. > > > > > -- > Steven Dear Sir, I redrafted it and reposted the question. This post I tried to drop but some how came. Please ignore this post. My reposting is with JSON. Regards, Subhabrata Banerjee. -- https://mail.python.org/mailman/listinfo/python-list
Question on Manipulating List and on Python
Dear Group, I have two questions one on list manipulation and other on Python. (i) I have a file of lists. Now, the first digit starts with a number or index, like, [001, "Obama", "USA", "President"] [002 "Major", "UK", "PM"] [003 "Singh", "INDIA", "PM"] Initially, I am reading the file and taking as for line in file: line_word=line.split print line_word I am getting the above result. But, my problem is if I read the array position 0, which is a number then it should give me reciprocal words like if word1=line_word[0] if word1==001: I should get line_word[1], line_word[2] reciprocating the value. Predefining it solves the problem, but I want to capture and do as it iterates. If any one can help? (ii) My second question is posted by one of my colleagues, what makes Python so fast? Regards, Subhabrata Banerjee. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Manipulating List and on Python
On Sep 29, 9:27 pm, John Gordon wrote: > In > Subhabrata Banerjee writes: > > > (i) I have a file of lists. Now, the first digit starts with a number > > or index, like, > > [001, "Obama", "USA", "President"] > > [002 "Major", "UK", "PM"] > > [003 "Singh", "INDIA", "PM"] > > Initially, I am reading the file and taking as > > for line in file: > > line_word=line.split > > print line_word > > This isn't your actual code. Please show us your real code, along with > a sample of your input file. > > > (ii) My second question is posted by one of my colleagues, what makes > > Python so fast? > > Fast compared to what? Why does your colleague believe it should be > slower? > > -- > John Gordon A is for Amy, who fell down the stairs > [email protected] B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" Hi John, The actual code is till now is: def name_debugger(n): open_file=open("/python27/name1.txt") for line in open_file: line_word=line.split() #print line_word word1=line_word[0] print word1 And Python seems faster than C++/Java. It is indeed. I also experience it. Regards, Subhabrata Banerjee. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on Manipulating List and on Python
On Sep 30, 12:52 am, "Prasad, Ramit" wrote: > -Original Message- > From: [email protected] > [mailto:[email protected]] On Behalf > Of Chris Angelico > Sent: Thursday, September 29, 2011 11:51 AM > To: [email protected] > Subject: Re: Question on Manipulating List and on Python > > On Fri, Sep 30, 2011 at 2:36 AM, Subhabrata Banerjee > wrote: > > And Python seems faster than C++/Java. It is indeed. I also experience > > it. > > Python compared to Java? Difficult to compare. Python to C++? > Impossible to compare. But performance depends MASSIVELY on > algorithmic quality; if you code the exact same thing in Python and in > C++, you would probably find that the C++ one is faster, but chances > are you're implementing approximately the same thing in two quite > different ways. Or possibly you're using a slow and inefficient > library or third-party function. > > I've sometimes written code in one language and directly ported it to > another, and then run both on the same hardware. With most such > experiments, CPython generally doesn't perform all that well, and C or > C++ rocks. But frequently, the C/C++ code is more verbose and more > error-prone than the Python - because Python's biggest boast is not > that it's fast, but that it's *fast enough*, while being easy to work > with. (And every once in a while there's something where I want to use > a pointer to some other variable, and that's a concept that just plain > doesn't work in Python. You have references to objects, but you can't > from one place change another variable, without using some kind of > mutable object that they both reference.) > --- > > I think Steven D'Aprano had an excellent post on this a week or so ago (on > the tutor list, not this one). > > See:http://mail.python.org/pipermail/tutor/2011-September/085573.html > > Ramit > > Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology > 712 Main Street | Houston, TX 77002 > work phone: 713 - 216 - 5423 > > ChrisA > --http://mail.python.org/mailman/listinfo/python-list > This email is confidential and subject to important disclaimers and > conditions including on offers for the purchase or sale of > securities, accuracy and completeness of information, viruses, > confidentiality, legal privilege, and legal entity disclaimers, > available athttp://www.jpmorgan.com/pages/disclosures/email. > > Dear Group, Thanks for your suggestions. I'll check if these work. Converting to dictionary I was thinking but others I have to test. Without patting my own back(I do not write algorithms that good), I can say Python is indeed damn fast. A reason many of my friends are shifting fast to Python and I was suggested by a reputed person of MIT CogLab to use Python instead of C++ and it worked just fabulous for me. To my collegue I would find out an answer. Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: File handling problem.
Dear Group,
I am working on a code like the following:
from decimal import*
#SAMPLE TEST PROGRAM FOR FILE
def sample_file_test(n):
#FILE FOR STORING PROBABILITY VALUES
open_file=open("/python26/Newfile1.txt","r+")
#OPENING OF ENGLISH CORPUS
open_corp_eng=open("/python26/TOTALENGLISHCORPUS1.txt","r")
#READING THE ENGLISH CORPUS
corp_read=open_corp_eng.read()
#CONVERTING THE CORPUS FILE IN WORDS
corp_word=corp_read.split()
#EXTRACTING WORDS FROM CORPUS FILE OF WORDS
for word in corp_word:
#COUNTING THE WORD
count1=corp_word.count(word)
#COUNTING TOTAL NUMBER OF WORDS
count2=len(corp_word)
#COUNTING PROBABILITY OF WORD
count1_dec=Decimal(count1)
count2_dec=Decimal(count2)
getcontext().prec = 6
prob_count=count1_dec/count2_dec
print prob_count
string_of_prob_count=str(prob_count)
file_input_val=open_file.write(string_of_prob_count)
open_file.close()
The problems I am getting:
(i) The probability values are not being stored properly in
file.
(ii)“Newfile1.txt” is storing not the series of values but
an arbitrary value from series 0.0143096
(iii) As I was testing it again it gave me another error
Traceback (most recent call last):
File "", line 1, in
sample_file_test(1)
File "C:\Python26\testprogramforfiles1.py", line 25, in sample_file_test
file_input_val=open_file.write(string_of_prob_count)
ValueError: I/O operation on closed file
If you can kindly let me know what is the wrong I am doing here.
As I took out the code pasted it in MS-Word before posting, there may be
slight indentation problem.
Best Regards,
Subhabrata.
On Sat, May 2, 2009 at 2:16 PM, Pascal Chambon wrote:
> [email protected] a écrit :
>
>> Dear Group,
>>
>> I am using Python2.6 and has created a file where I like to write some
>> statistical values I am generating. The statistical values are
>> generating in a nice way, but as I am going to write it, it is not
>> taking it, the file is opening or closing properly but the values are
>> not getting stored. It is picking up arbitrary values from the
>> generated set of values and storing it. Is there any solution for it?
>>
>> Best Regards,
>> SBanerjee.
>> --
>> http://mail.python.org/mailman/listinfo/python-list
>>
>>
>>
>>
> Hello
>
> Could you post excerpt of your file-handling code ?
> It might be a buffering problem (although when the file closes, I think
> buffers get flushed), else it's really weird...
>
> Regards,
> pascal
>
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: File handling problem.
Dear Sir,
Thanx for your prompt reply, I would be trying to work on your suggestion
and get back to you as soon as possible.
Best Regards,
Subhabrata.
On Sun, May 3, 2009 at 10:47 PM, Chris Rebert wrote:
> On Sun, May 3, 2009 at 9:51 AM, SUBHABRATA BANERJEE
> wrote:
> > Dear Group,
> >
> >
> >
> > I am working on a code like the following:
> >
> >
> >
> > from decimal import*
> >
> > #SAMPLE TEST PROGRAM FOR FILE
> >
> > def sample_file_test(n):
> >
> > #FILE FOR STORING PROBABILITY VALUES
> >
> > open_file=open("/python26/Newfile1.txt","r+")
>
> Is there a reason you must output the results to the same file the
> input came from? It's possible this is part of your problems.
>
> >
> > #OPENING OF ENGLISH CORPUS
> >
> > open_corp_eng=open("/python26/TOTALENGLISHCORPUS1.txt","r")
> >
> > #READING THE ENGLISH CORPUS
> >
> > corp_read=open_corp_eng.read()
> >
> > #CONVERTING THE CORPUS FILE IN WORDS
> >
> > corp_word=corp_read.split()
> >
> > #EXTRACTING WORDS FROM CORPUS FILE OF WORDS
> >
> > for word in corp_word:
> >
> > #COUNTING THE WORD
> >
> > count1=corp_word.count(word)
>
> Note: Your program is currently O(N^2) rather than O(N) because you
> re-count the number of occurrences of each word /on every occurrence
> of the word/.
>
> > #COUNTING TOTAL NUMBER OF WORDS
> >
> > count2=len(corp_word)
> >
> > #COUNTING PROBABILITY OF WORD
> >
> > count1_dec=Decimal(count1)
> >
> > count2_dec=Decimal(count2)
> >
> > getcontext().prec = 6
> >
> > prob_count=count1_dec/count2_dec
> >
> > print prob_count
> >
> > string_of_prob_count=str(prob_count)
> >
> > file_input_val=open_file.write(string_of_prob_count)
> >
> > open_file.close()
>
> You shouldn't be closing the file until the /entire loop/ has finished
> writing to the file. So the previous line should be dedented.
>
> >
> >
> >
> > The problems I am getting:
> >
> > (i) The probability values are not being stored properly
> in
> > file.
>
> Also, you're currently not putting any separator between consecutive
> entires, so it's all going to run together as one long line.
> Have you considered using one of the std lib modules to output the
> file in a well-defined human-readable format such as JSON or CSV?
>
> > (ii)“Newfile1.txt” is storing not the series of values
> but
> > an arbitrary value from series 0.0143096
> >
> > (iii) As I was testing it again it gave me another error
> >
> > Traceback (most recent call last):
> >
> > File "", line 1, in
> >
> > sample_file_test(1)
> >
> > File "C:\Python26\testprogramforfiles1.py", line 25, in
> sample_file_test
> >
> > file_input_val=open_file.write(string_of_prob_count)
> >
> > ValueError: I/O operation on closed file
>
>
> Cheers,
> Chris
> --
> http://blog.rebertia.com
>
--
http://mail.python.org/mailman/listinfo/python-list
Re: Creating a web page with Python
Dear Mike, Thanx your solutions came to the very point. And you understood the problem so nicely. It is just perfect. Great. Regards, Subhabrata Banerjee. Mike Driscoll wrote: > On May 27, 9:25�am, [EMAIL PROTECTED] wrote: > > Dear Members of the group, > > If any one can help me with an idea how to create a web page with > > python? Do I have to use vbscript or something like that? I also want > > to embed the function in the button of a form. How can I do it in > > Python? > > Regards, > > Subhabrata Banerjee. > > > There are many ways to do this. You can use Python kind of like cgi: > > http://www.python.org/doc/essays/ppt/sd99east/index.htm > http://docs.python.org/lib/module-cgi.html > > WSGI: http://www.wsgi.org/wsgi > > Web Frameworks: Django, TurboGears, Pylons, mod-python, Zope/Plone > > Or you might just want to browse Python's wiki: > > http://wiki.python.org/moin/WebProgramming > > Mike -- http://mail.python.org/mailman/listinfo/python-list
Problem with py2exe
Dear Members of the group, py2exe does not seem to be integrating with 2.5 or later versions. I was trying to run it but requested only for 2.3. How can I run it? If any one can kindly help. Regards, Subhabrata Banerjee. -- http://mail.python.org/mailman/listinfo/python-list
Error handling in Python
Dear Members of the group, If I open a url by urlopen in the urllib, the file is either opening a file or if no url is there it would give error. The error is generated can be handled by IOError handling schemes. But if there are thousands or millions of URLs and I do not know who will open and who won't open. How can I handle this kind of situation? If any one can help solving this problem. Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: best way to create a timer
You can think of doing with import time module and time.sleep(n) but you have to calculate n in seconds. Subhabrata. Alexnb wrote: > I am wondering what is the best way to create a timer, like an alarm, once it > reaches a time, it triggers an event. I have a way of doing this but it > seems like it isn't good at all. If it helps at all I am using a Tkinter, > but that probably doesn't mean much. The way I was doing it was using a > while loop, and just saying while current time is not = to trigger time, do > nothing, and when it is, do event. > -- > View this message in context: > http://www.nabble.com/best-way-to-create-a-timer-tp17815502p17815502.html > Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list
HTML FORM AND PYTHON
Dear Members of the group, I have a small question, if you can help me to find the answer. I have one function: def add_string(n): print “Print Two strings” print “Print the First String” a1=raw_input(“PRINT THE FIRST STRING”) a2=raw_input(“PRINT THE SECOND STRING”) print “CONCATENATING THE TWO GIVEN STRINGS” a3=a1+a2 print “THE RESULT IS” print a3 Now, I have designed one HTML form which has two input fields for text and an output field for the result. I like to bind the python program into HTML form. i) Is there any way I can keep both my existing python code and HTML code and bind them? If any one can suggest with example. ii) Do I have to write the whole code in a way in python so that it would work the function as well as generate HTML form I am looking for? If any one can suggest with example. iii) Is there any other way? Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: hi
Islam is a nice religion if you read The quran. Militancy is their in every religion. But unfortunately, Islam is getting a bad name. It is good to see that some one like you is trying to let us know the good part of it. But this may not be a room for that. You might have been wrongly directed here. islamvoice wrote: > hi > My name is amira , I am from ( egypt), > I’ve seen many places of the world on TV screen and few that > I’ve visited either for fun or/and business > As you know when we travel we meet a lot of different cultures and > people, > I found in many places I’ve been to; that people stereotyped > Islam (that''s my religion) they prejudge Muslims from what they see > in media incidents. > Allow me to share with you here some information about Jesus Christ, > Muslims believe in Jesus Christ (peace and blessings of (Allah = God) > be upon Him as one of the mightiest messengers from (Allah=God), > We believe he is born miraculously by the word of Allah without Father > Like ADAM Been created without father nor mother, > And Marry (mar yam) is his mother the pious, pure female may Allah be > pleased with her, > In fact there is a chapter in Quraan titled Marry > Let me quote here these verses: > “BEHOLD! THE ANGELS SAID: O MARY! GOD HATH CHOSEN THEE AND > PURIFIED THEE – > CHOSEN THEE ABOVE THE WOMEN OF ALL NATIONS ” > And this Verse About Jesus: > “HE SHALL SPEAK TO THE PEOPLE IN CHILDHOOD AND IN MATURITY, AND > SHALL BE (OF THE COMPANY) OF THE RIGHTEOUS.” > If this is a Quiz asking you where these Divine verses come from the > Bible Torah or elsewhere? > THE Answer for your information it is from Quraan 3:45,46 > This shows how much we need to know about what others believe. > You may visit this link below it’ll give you broad knowledge of > Islam in Questions and Answers format , > > http://www.islam-qa.com/ > Or > http://www.islam-online.net/ > Or > http://www.al-islam.com/ > Or > http://www.al-sunnah.com/ > Listen I am NOT Trying to convert YOU, but isn''t it worth it for > general > Information to know about what other believes? > And Allah granted you and me wisdom, brain, and heart to judge for > ourselves? > Needless to say if you have any comment, question, suggestion I''ll be > glad to share them with you. > ��� ��� � ��� �� ��� �� � � > Okay if you found my introductory bothersome in any way please > Forgive me, > �Any way I hope to hear from you sooner, > > ***Your Name *** > > > > Excuse me!! > Would you stop for a moment?! > O...man...Haven''t you thought-one day- about yourself ? > Who has made it? > Have you seen a design which hasn''t a designer ?! > Have you seen a wonderful,delicate work without a worker ?! > It''s you and the whole universe!.. > Who has made them all ?!! > You know who ?.. It''s "ALLAH",prise be to him. > Just think for a moment. > How are you going to be after death ?! > Can you believe that this exact system of the universe and all of > these great creation will end in in nothing...just after death! > Have you thought, for a second, How to save your soul from Allah''s > punishment?! > Haven''t you thought about what is the right religion?! > Read ... and think deeply before you answer.. > It is religion of Islam. > It is the religion that Mohammad-peace upon him- the last prophet, had > been sent by. > It is the religion that the right Bible- which is not distorted-has > preached. > Just have a look at The Bible of (Bernaba). > Don''t be be emotional . > Be rational and judge.. > Just look..listen...compare..and then judge and say your word. > We advise you to visit : > http://www.al-sunnah.com/ > http://www.thetruereligion.org/ > http://www.sultan.org/ > http://www.islam-qa.com/ > > > > Didn''t you asked your self one-day: > What''s The Purpose of life? > Here you will get the answer: > Audio > http://www.sultan.org/articles/purposeoflife.htm > What Does Islam Say About Life''s Purpose? > Have you ever asked yourself these questions? > "What is the purpose of L I F E?" > "My life?" > "Your Life?" > http://www.islamtomorrow.com/purpose.htm > > > > Do you want to know about ISLAM, the fastest growing religion in the > World?If yes, please visit this site > http://islam-guide.com/ > > > > Learn about the fastest growing religion in the World: > http://www.i-g.org/ > > > > > For The Seekers of Truth > > http://www.i-g.org/ > > > > Do You Really Want The Truth About islam? > > http://www.al-sunnah.com/ > http://www.i-g.org/ > > > > Why should you be a Muslim ? > http://english.islamway.com/bindex.p...=39&scholar_id =5 > > > > Best way to live and die > http://www.al-sunnah.com/bestway.htm > > > > HOW TO BECOME A > MUSLIM > http://www.islamworld.net/become.html > > > > Questions And Answers On Islamic Monotheism50 > > http://www.al-sunnah.com/50q.htm > > > > Who is Allah – > ( Allah is the Arabic word for God) > We Are More Worthy of Jesus Than They Are > > http://islaam.com/audio/lectures/yi/ram/yijesus1.ram > The True Religion >
Re: error showing file not found
You can see the file whether it is loaded in C:\Python and you entered it correctly. Problem should not occur. Else you may refer Python docs for Error and Exception handling. Regs, Subhabrata. [EMAIL PROTECTED] wrote: > Hi, > I am new to python.I have installed Biopython in Windows.I am working > using IDLE.When I want to get structure of local pdb file it is showing > error that "no such file or directory".Can anybody tell what is the > problem. > > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. > > > -- > This message has been scanned for viruses and > dangerous content by MailScanner, and is > believed to be clean. -- http://mail.python.org/mailman/listinfo/python-list
Re: HTML FORM AND PYTHON
Hi Diez, Thanx for the suggestion. I am checking if anything helpful I can find there. Regards, Subhabrata. Diez B. Roggisch wrote: > [EMAIL PROTECTED] schrieb: > > Dear Members of the group, > > I have a small question, if you can help me to find the answer. > > I have one function: > > def add_string(n): > > print �Print Two strings� > > print �Print the First String� > > a1=raw_input(�PRINT THE FIRST STRING�) > > a2=raw_input(�PRINT THE SECOND STRING�) > > print �CONCATENATING THE TWO GIVEN STRINGS� > > a3=a1+a2 > > print �THE RESULT IS� > > print a3 > > > > Now, I have designed one HTML form which has two input fields for text > > and an output field for the result. > > > > I like to bind the python program into HTML form. > > i) Is there any way I can keep both my existing python code and HTML > > code and bind them? If any one can suggest with example. > > No. The above code works with user-interation at certain points of the > program. That can't be (easily, and especially not with the above > functionality) translated into the http-paradigm where each operation is > embedded into a request/resonse-cycle, with the need for explicit or > implicit state-keeping over these cycles. > > > ii) Do I have to write the whole code in a way in python so that it > > would work the function as well as generate HTML form I am looking > > for? If any one can suggest with example. > > For this *trivial* example, I can only say: there isn't enough to be > worth abstracting. > > > iii) Is there any other way? > > Google python + webframeworks to find a bazillion discussions, opinions, > examples. > > Diez -- http://mail.python.org/mailman/listinfo/python-list
Question on time module
Dear Members of the group, I have one function def sum1(n): a1=5 a2=6 a3=a1+a2 a4=a3+8 print "The First sum is" print a3 print "The Second sum is" print a4 Now, I want to do it in a way, a4 is calculated after a given time interval of a3 -this is easy but if I want to check after how much time a4 is calculated from a3 how can I do? If any one can help it. Best Regards, Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Re: Question on time module
This problem is solved with time.gmtime [EMAIL PROTECTED] wrote: > Dear Members of the group, > I have one function > def sum1(n): > a1=5 > a2=6 > a3=a1+a2 > a4=a3+8 > print "The First sum is" > print a3 > print "The Second sum is" > print a4 > > Now, I want to do it in a way, a4 is calculated after a given time > interval of a3 -this is easy but if I want to check after how much > time a4 is calculated from a3 how can I do? > If any one can help it. > Best Regards, > Subhabrata. -- http://mail.python.org/mailman/listinfo/python-list
Question on List
Dear All,
I am trying to write the following code:
def try1(n):
a1="God Godess Borother Sister Family"
a2=a1.split()
a3=raw_input("PRINT A WORD")
a4=a1.find(a3)
print a4
a5=[]
if a4>0:
a5=a2.index(a3)
a6=a5+1
a7=a2[a6]
print "The new word is"
print a7
a8=a5.append(a7)
print a5
elif a4<0:
a11=a3
print "The word is not availiable in String"
print a11
a6=a5.append(a11)
print a5
else:
print "Error"
Now, my question is I like to see a5 or the empty list as appended
with elements. Results I am getting is a5 giving single value like
['God'],['Godess']... but I like to see it as ['God','Godess'...] etc.
Am I going wrong?
Do I have to rethink it in some other way?
If any one can kindly let me know.
Best Regards,
Subhabrata.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Question on List
Hi Chris,
I solved the problem some other way round but thanx for your
suggestion, I'll review it also.
Best Regards,
Subhabrata.
Chris wrote:
> On Jun 27, 9:51�am, [EMAIL PROTECTED] wrote:
> > Dear All,
> > I am trying to write the following code:
> >
> > def try1(n):
> > � � � � a1="God Godess Borother Sister Family"
> > � � � � a2=a1.split()
> > � � � � a3=raw_input("PRINT A WORD")
> > � � � � a4=a1.find(a3)
> > � � � � print a4
> > � � � � a5=[]
> > � � � � if a4>0:
> > � � � � � � � � a5=a2.index(a3)
> > � � � � � � � � a6=a5+1
> > � � � � � � � � a7=a2[a6]
> > � � � � � � � � print "The new word is"
> > � � � � � � � � print a7
> > � � � � � � � � a8=a5.append(a7)
> > � � � � � � � � print a5
> > � � � � elif a4<0:
> > � � � � � � � � a11=a3
> > � � � � � � � � print "The word is not availiable in String"
> > � � � � � � � � print a11
> > � � � � � � � � a6=a5.append(a11)
> > � � � � � � � � print a5
> > � � � � else:
> > � � � � � � � � print "Error"
> >
> > Now, my question is I like to see a5 or the empty list as appended
> > with elements. Results I am getting is a5 giving single value like
> > ['God'],['Godess']... but I like to see it as ['God','Godess'...] etc.
> > Am I going wrong?
> > Do I have to rethink it in some other way?
> > If any one can kindly let me know.
> > Best Regards,
> > Subhabrata.
>
> First notes, the string .find() method return -1 for not found and
> zero or above if the search string is present. Remember you count
> from zero. Secondly, list .append() methods do not return a new list
> but modify the list in place. Thirdly, the .index() method of a list
> requires an integer and not a string. And lastly, indentation should
> be 4 spaces not 8.
>
> Just doing a sloppy job on the code (and my interpretation of what you
> wanted)
>
> def try1(n):
> new_list = []
> input_string="God Godess Borother Sister Family"
> while n:
> user_selection=raw_input("PRINT A WORD")
> if input_string.find(user_selection) > -1:
> s = input_string.split()
> i = [i for i,j in enumerate(s) if j == user_selection]
> new_word = s[i+1]
> print 'The new word is %s' % new_word
> new_list.append(new_word)
> print new_list
> else:
> print 'User selection of "%s" not in the string.' %
> user_selection
> new_list.append(user_selection)
> print new_list
> n -= 1
>
> Obviously I'm going to assume that the code you posted excluded your
> loop control for the "try n amount of times". What was most likely
> the cause is that you loop through your structure for every attempt of
> the n times but each time you reset your list when you re-create it.
>
> Hope that helps some.
> Chris
--
http://mail.python.org/mailman/listinfo/python-list
PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.
I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v. 1310 32 bit (Intel)] on win32 with IDLE 1.2.1 My O/S is Windows XP SP2 I use 512 MB RAM. I am encountering the following problems: (i) a1=1 a2=2 a3=a1+a2 print a3 # The result is coming sometimes as 3 sometimes as vague numbers. (ii) x1="Bangalore is called the Silicon Valley of India" x2="NewYork" x3=x1.find(x2) print x3 # The result of x3 is coming as -1 as well as +ve numbers. (iii) I have been designing one crawler using "urllib". For crawling one web page it is perfect. But when I am giving around 100 URLs by and their links and sublinks the IDLE is not responding. Presently I have been running with 10 URLs but can't it be ported? (iv) I have designed a program with more than 500 if elif else but sometimes it is running fine sometimes it is giving hugely erroneous results, one view of the code: elif a4==3: print "YOU HAVE NOW ENTERED THREE WORDS" if a3[0] not in a6: if a3[1] not in a6: if a3[2] not in a6: print "a3[0] not in a6, a3[1] not in a6, a3[2] not in a6" elif a3[2] in a6: print "a3[0] not in a6, a3[1] not in a6, a3[2] in a6" else: print "NONE3.1" elif a3[1] in a6: if a3[2] not in a6: print "a3[0] not in a6, a3[1] in a6, a3[2] not in a6" elif a3[2] in a6: print "a3[0] not in a6,a3[1] in a6, a3[2] in a6" else: print "NONE3.2" else: print "NONE3.3" elif a3[0] in a6: if a3[1] not in a6: if a3[2] not in a6: print "a3[0] in a6, a3[1] not in a6, a3[2] not in a6" elif a3[2] in a6: print "a3[0] in a6, a3[1] not in a6, a3[2] in a6" else: print "NONE3.4" elif a3[1] in a6: if a3[2] not in a6: print "a3[0] in a6, a3[1] in a6, a3[2] not in a6" elif a3[2] in a6: print "a3[0] in a6, a3[1] in a6, a3[2] in a6" else: print "NONE3.5" else: print "NONE3.6" else: print "NONE3.7" Why it is behaving like that? If someone can help me. Best Regards, Subhabrata Banerjee, Indian Institute of Science, Bangalore, India. -- http://mail.python.org/mailman/listinfo/python-list
Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.
Dear Sir,
Thank you for taking time out to answer.
For (i) It is happening. On trial it ran so well that when on
demonstration I got questions from tester, I felt amazed.
For (ii) For answer no.2 I'll check str.find.
For (iii) Well I said you most of crawler's algorithm. It works like a
MS IE synchronizer, if not better. The URLs are taken in a file the
file is read the URL's taken and put into
urllib.urlopen("http://.";) as it crawls the result is stored in a
text file, from the text file the garbage is cleaned, the sublinks are
extracted, the result files are again cleaned and sublinks extracted
we carry on this till we reach an optimum. For n-gram calculaion of
sublinks I am using numpy and decimal and pattern search in a unique
combination, it has no prob but this IDLE is getting no response if I
port more than 10 sites. I am willing to put 100 to 1000 URLs at one
go. If you know anyone in Bangalore, India expert in python kindly
send him across I can show him the problem in my machine and Indian
Institute of Science(IISc-locally known as TATA INSTITUTE) is a
distinguished place.Any one should know it.
I am in no mood of doing a joke.
Best Regards,
Subhabrata Banerjee.
Steve Holden wrote:
> [EMAIL PROTECTED] wrote:
> > I am using Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.
> > 1310 32 bit (Intel)] on win32 with IDLE 1.2.1
> > My O/S is Windows XP SP2 I use 512 MB RAM.
> > I am encountering the following problems:
> > (i) a1=1
> > a2=2
> > a3=a1+a2
> > print a3
> > # The result is coming sometimes as 3 sometimes as vague numbers.
> >
> Sorry, this just isn't true. There is no known implementation for which
> 1+2 does not equal 3.
>
> > (ii) x1="Bangalore is called the Silicon Valley of India"
> > x2="NewYork"
> > x3=x1.find(x2)
> > print x3
> > # The result of x3 is coming as -1 as well as +ve numbers.
> >
> Presumably you get -1 when the substring isn't found. Look at the
> documentation of str.find() to discover *why* this happens.
>
> > (iii) I have been designing one crawler using "urllib". For crawling
> > one web page it is perfect. But when I am giving around 100 URLs by
> > and their links and sublinks the IDLE is not responding. Presently I
> > have been running with 10 URLs but can't it be ported?
> >
> Not enough information. "I have a program, please tell me waht is wrong
> with it" overtaxes even this group's psychic abilities.
>
> > (iv) I have designed a program with more than 500 if elif else but
> > sometimes it is running fine sometimes it is giving hugely erroneous
> > results, one view of the code:
>
> I am afraid that for code like this "designed" is far too kind a term. I
> would have suggested "thrown together".
>
> On what analysis of your problem was this solution based?
>
> > elif a4==3:
> > print "YOU HAVE NOW ENTERED THREE WORDS"
> > if a3[0] not in a6:
> > if a3[1] not in a6:
> > if a3[2] not in a6:
> > print "a3[0] not in a6, a3[1] not in a6, a3[2] not
> > in a6"
> > elif a3[2] in a6:
> > print "a3[0] not in a6, a3[1] not in a6, a3[2] in
> > a6"
> > else:
> > print "NONE3.1"
> > elif a3[1] in a6:
> > if a3[2] not in a6:
> > print "a3[0] not in a6, a3[1] in a6, a3[2] not in
> > a6"
> > elif a3[2] in a6:
> > print "a3[0] not in a6,a3[1] in a6, a3[2] in a6"
> > else:
> > print "NONE3.2"
> > else:
> > print "NONE3.3"
> > elif a3[0] in a6:
> > if a3[1] not in a6:
> > if a3[2] not in a6:
> > print "a3[0] in a6, a3[1] not in a6, a3[2] not in
> > a6"
> > elif a3[2] in a6:
> > print "a3[0] in a6, a3[1] not in a6, a3[2] in a6"
> > else:
> > print "NONE3.4"
> > elif a3[1] in a6:
> >if a3[2] not in a6:
> >print "a3[0] in a6, a3[1] in a6, a3[2] not in a6"
> >elif a3[2] in a6:
> >print "a3[0] in a6, a3[1] in a6, a3[2] in a6"
> >else:
> >print "NONE3.5"
> > else:
> > print "NONE3.6"
> > else:
> > print "NONE3.7"
> > Why it is behaving like that?
>
> Like what? You don't even say what results you expect, and only describe
> the results you *do* obtain as "hugely erroneous".
>
> I have a car. I have turned the ignition key but it fails to start.
> Please tell me what is wrong with it.
>
> regards
> Steve
> --
> Steve Holden+1 571 484 6266 +1 800 494 3119
> Holden Web LLC http://www.holdenweb.com/
--
http://mail.python.org/mailman/listinfo/python-list
Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.
Hi Steve, comp.lang.python is supposed to be a serious group not anyone knowing nothing and giving comment. Well, original code snippet I don't know why an expert person like you fails to understand, I told it almost can't you guess the next portion? Tough indeed, then. I've to take permission from my organization if we can bring out this code in public domain as we are working out an MT system that performs better than Systran. And if it is a public domain I donot have security for my code. Any one can copy. But well if this group people are helping out of kindness, then I have to think. I thought if you know then only you can help. I am waiting for a knowledgeable answer from a knowledgeable person. I think I can show a person right direction only if I know it, that is not kindness but power of my knowledge. Let me solve it myself only, I will let you know how I solved them and with many are quite innovative. Like you can use index or re.search or in/not in instead of find Sad to have a response from a person like you I had just great hope, and when python can be coded so fast. Best Regards, Subhabrata. Steve Holden wrote: > [EMAIL PROTECTED] wrote: > [...] > > > If you know anyone in Bangalore, India expert in python kindly > > send him across I can show him the problem in my machine and Indian > > Institute of Science(IISc-locally known as TATA INSTITUTE) is a > > distinguished place.Any one should know it. > > I am in no mood of doing a joke. > > [...] > > >> I have a car. I have turned the ignition key but it fails to start. > >> Please tell me what is wrong with it. > >> > Please understand: this is the Internet. The chances that a random > responder will know anyone in Bangalore are vanishingly small. > > I wasn't joking: I was simply (perhaps sarcastically) pointing out that > you do not provide enough information for anyone to help with your > problem, since you don't explain what the problem is. > > Fortunately nobody is under any obligation to help here, it's simply > done out of kindness. > > regards > Steve > -- > Steve Holden+1 571 484 6266 +1 800 494 3119 > Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: PROBLEMS WITH PYTHON IN SOME VARIABLE,FUNCTIONS,ETC.
I am getting the comments. So any one can post any comment like Steve knows nothing of Python. California has still lot to catch up to be at par with Mesopatamia. comp.lang.python seems a group of fools. Anyhow, all I learnt take whichever suits and ignore rest many people have lot of time to carry out lot of nonsense. Well I should have looked for a paid help and my stand about not giving out my code in open forum stands as prolific. Better not lose time unnecessarily going back to work and debugging the problems is much sensical work that I can do instead of listening to jokes in the morning Marc 'BlackJack' Rintsch wrote: > On Wed, 09 Apr 2008 16:16:14 +0200, Diez B. Roggisch wrote: > > > And then you reply telling us about the greatness of Bangalore and your > > product to come. Which is somewhat amusing that people who claim to produce > > the greatest software being incapable of debugging it deems me as odd - to > > say the least. > > That's not odd, that's perfectly normal for really clever code: > > Debugging is twice as hard as writing the code in the first > place.Therefore, if you write the code as cleverly as possible, you > are, by definition, not smart enough to debug it. -- Brian W. Kernighan > > ;-) > > Ciao, > Marc 'BlackJack' Rintsch -- http://mail.python.org/mailman/listinfo/python-list
