Re: [Tutor] library terminology and importing

2016-02-21 Thread Martin A. Brown

Good morning,

I'm inverting the order of your questions, because I think the order of the
answers may help.

>But if I import all of os and datetime, I can use those functions by
>writing the full 'path' 3 levels deep:
>
>os.path.expanduser('~')
>datetime.datetime.now()

[... hold onto your hat, we'll get to datetime.datetime ...]

>from os.path import join,expanduser
>
>Also, is there proper terminology for each of the 3 sections of
>os.path.expanduser('~') for example?  Such as

Yes, there most certainly is; it's good that you are asking.  See below.

>os - library (or module?)
>path - ?
>expanduser - function

Here's how you could figure out what they are called.  Use 'type' to figure
it out:

  >>> import os
  >>> type(os)
  

  >>> type(os.path)
  

  >>> type(os.path.expanduser)
  

Observe that the type of os.path.expanduser is function.

It is for this reason that you can importi (and use) the expanduser 
function by itself.  It can stand alone:

  >>> from os.path import expanduser
  >>> type(expanduser)
  

Side note, for diagnostics, 'type' can be handy, also, for things 
like:

  >>> type('word')
  
  >>> type(7)
  

>I often use now() and strftime() from datetime, but it seems like I can't
>import just those functions.  The os module allows me to import like this:

Ok, so back to datetime...

  >>> type(datetime)
  

This should not surpise you.  So, datetime is a module.  Good.

  >>> type(datetime.datetime)
  

Oh-ho!  What is this one?  It's called 'type'?  Well, it's a Python 
class.  You can see it in the source code, if you look for the class 
definition of 'datetime' in the module 'datetime'.  I find mine in 
/usr/lib64/python3.4/datetime.py around line 1290ff.  Look for this:

  class datetime(date):
  """datetime(year, month, day[, hour[, minute[, second[, 
microsecond[,tzinfo])

Why am I pointing you to this?  Well, in particular, you should see the
following a few lines later (lines 1394 ff in my copy):

@classmethod
def now(cls, tz=None):
"Construct a datetime from time.time() and optional time zone info."
t = _time.time()
return cls.fromtimestamp(t, tz)

If you wish, you can go look up the decorator @classmethod and what 
it does, but the main point I'm making here is that this is not a 
function!  It cannot be separated from the datetime class.  It is 
(in this case) an alternate constructor for a datetime object.  And, 
'type' will tell you so:

  >>> type(datetime.datetime.now)
  

So, even though the name is available to you and callable, when you 
import the module datetime, you can't separate the classmethod 
called 'now()' from the datetime.datetime class.

>but I get an error if I try
>
>from datetime.datetime import now, strftime

If you are mostly interested in shortening your import statement, I have seen
people use this sort of technique:

  >>> from datetime import datetime as dt
  >>> now = dt.now()
  >>> now.strftime('%F-%T')
  '2016-02-21-18:30:37'

Good luck and enjoy,

-Martin

-- 
Martin A. Brown
http://linux-ip.net/
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library terminology and importing

2016-02-21 Thread Ben Finney
street.swee...@mailworks.org writes:

> I get an error if I try
>
> from datetime.datetime import now, strftime

‘datetime.datetime’ is not a module, so you can not import objects from
it.

> But if I import all of os and datetime, I can use those functions by
> writing the full 'path' 3 levels deep:
>
> os.path.expanduser('~')
> datetime.datetime.now()

Yes. That's a good way to do it, because it makes your code explicit and
clear to read.

> Is there a way to import individual functions from datetime.datetime?

Don't try to do that. Namespaces are a honking good idea in Python, you
should not seek to avoid them.

-- 
 \ “I may disagree with what you say, but I will defend to the |
  `\death your right to mis-attribute this quote to Voltaire.” |
_o__)   —Avram Grumer, rec.arts.sf.written, 2000-05-30 |
Ben Finney

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library for .ppt to .txt conversion

2014-05-31 Thread Aaron Misquith
The only thing i want from the ppt's is text and ignoring all graphical
representations. I need the text to perform various nltk operations.


On Fri, May 30, 2014 at 11:54 PM, Alan Gauld alan.ga...@btinternet.com
wrote:

 On 30/05/14 10:41, Aaron Misquith wrote:

 Like pypdf is used to convert pdf to text; is there any library that is
 used in converting .ppt files to .txt? Even some sample programs will be
 helpful.


 Bearing in mind that Powerpoint is intended for graphical presentations
 the text elements are not necessarily going to be useful. Often Powerpoint
 text is actually part of a graphic anyway.

 If the Powerpoint is just a set of bullet points (shame on the presenter!)
 you probably don't want the text unless you can
 also get the notes. I don't know of any libraries that can do that.

 But one option  is that Open/Libre office can import Powerpoint and
 apparently has a Python API which you could use to drive an export
 from there. Just a thought...

 --
 Alan G
 Author of the Learn to Program web site
 http://www.alan-g.me.uk/
 http://www.flickr.com/photos/alangauldphotos

 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 https://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library for .ppt to .txt conversion

2014-05-31 Thread Dave Angel
Aaron Misquith aaronmisqu...@gmail.com Wrote in message:


 The only thing i want from the ppt's is text and ignoring all graphical 
representations. I
  need the text to perform various nltk operations.


 On Fri, May 30, 2014 at 11:54 PM, Alan Gauld alan.ga...@btinternet.com 
 wrote:
 Bearing in mind that Powerpoint is intended for graphical presentations the 
 text 
 elements are not necessarily going to be useful. Often Powerpoint text 
 is actually part of a graphic anyway.


1. please don't top-post.  Place your comments after the quoted
 text from the previous message. Please tell your mail program to
 use text, not html when posting here.

2. Alan has pointed out that there may not be any text in the ppt
 file,  but just image data that represents the text.   Similar to
 the way a scanned piece of paper has no text till you try to ocr
 it.


-- 
DaveA

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library for .ppt to .txt conversion

2014-05-30 Thread Marc Tompkins
On Fri, May 30, 2014 at 2:41 AM, Aaron Misquith aaronmisqu...@gmail.com
wrote:

 Like pypdf is used to convert pdf to text; is there any library that is
 used in converting .ppt files to .txt? Even some sample programs will be
 helpful.


I suspect you'd need to use PowerPoint itself to do that cleanly; you can
definitely drive PowerPoint from Python if you so desire, though:
http://www.s-anand.net/blog/automating-powerpoint-with-python/

If anybody's written a package to brute-force the text out of a .ppt file
without using PowerPoint, though, I'm unaware of it.  That way lies
madness, I suspect.  (The new MS Office formats - .docx, .xlsx, .pptx - are
XML files inside of a renamed ZIP container; it should be fairly easy to
get the text out of a .pptx file using any one of Python's XML libraries.
But the older format is proprietary and extremely scary.)
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library for .ppt to .txt conversion

2014-05-30 Thread Alan Gauld

On 30/05/14 10:41, Aaron Misquith wrote:

Like pypdf is used to convert pdf to text; is there any library that is
used in converting .ppt files to .txt? Even some sample programs will be
helpful.


Bearing in mind that Powerpoint is intended for graphical presentations 
the text elements are not necessarily going to be useful. Often 
Powerpoint text is actually part of a graphic anyway.


If the Powerpoint is just a set of bullet points (shame on the 
presenter!) you probably don't want the text unless you can

also get the notes. I don't know of any libraries that can do that.

But one option  is that Open/Libre office can import Powerpoint and
apparently has a Python API which you could use to drive an export
from there. Just a thought...

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.flickr.com/photos/alangauldphotos

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library:

2013-08-21 Thread Steven D'Aprano
On Tue, Aug 20, 2013 at 10:00:24PM -0500, William Crowder wrote:

   I am reading posts and watching videos. I am following along 
   with the shell, i am retaining the info. But WHAT is a library?


In English, a library is a collection of books, or magazines. 

A software library is a collection of programs or functions, instead 
of books. Sometimes it will be one file, with many functions. Sometimes 
it will be many files.

In Python:

import math


will load the math library, so you can use functions like math.sin, 
math.sqrt, and others.

Does this answer your question? If you need more help, please ask.


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library:

2013-08-21 Thread Joel Goldstick
On Wed, Aug 21, 2013 at 4:29 AM, Steven D'Aprano st...@pearwood.info wrote:
 On Tue, Aug 20, 2013 at 10:00:24PM -0500, William Crowder wrote:

   I am reading posts and watching videos. I am following along
   with the shell, i am retaining the info. But WHAT is a library?


In python libraries are called modules I believe.  So you may see
either term, and unless someone here corrects me, they are the same.

 In English, a library is a collection of books, or magazines.

 A software library is a collection of programs or functions, instead
 of books. Sometimes it will be one file, with many functions. Sometimes
 it will be many files.

 In Python:

 import math


 will load the math library, so you can use functions like math.sin,
 math.sqrt, and others.

 Does this answer your question? If you need more help, please ask.


 --
 Steven
 ___
 Tutor maillist  -  Tutor@python.org
 To unsubscribe or change subscription options:
 http://mail.python.org/mailman/listinfo/tutor



-- 
Joel Goldstick
http://joelgoldstick.com
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library:

2013-08-21 Thread Chris Down
On 2013-08-21 13:31, Joel Goldstick wrote:
 In python libraries are called modules I believe.  So you may see
 either term, and unless someone here corrects me, they are the same.

They are often interchangeable, but they do not have to be the same (for
example, it is perfectly imaginable that a library contains multiple modules),
since library is an aesthetic constraint, but module isn't.


pgpuc2BqPHS6p.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library:

2013-08-21 Thread Alan Gauld

On 21/08/13 04:00, William Crowder wrote:

I am reading posts and watching videos. I am following along with the
shell, i am retaining the info. But WHAT is a library?


It varies but in general programming terms is a collection of functions 
or classes that can be reused by programmers. Most languages have a 
standard library and a collection of additional proprietary libraries.

Python's standard library  consists of a set of modules, each of which
exposes a set of functions or classes for performing related tasks.

The documentation for Python's standard library (V2) can be found here:

http://docs.python.org/2/py-modindex.html

The documentation for GNU C++'s standard library is here:

http://gcc.gnu.org/onlinedocs/libstdc++/libstdc++-api-4.6/modules.html

And for Java it is here:

http://docs.oracle.com/javase/7/docs/api/

It's interesting to compare their breadth and nature.

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library:

2013-08-21 Thread Chris Down
On 2013-08-21 23:30, Alan Gauld wrote:
 It varies but in general programming terms is a collection of functions or
 classes that can be reused by programmers. Most languages have a standard
 library and a collection of additional proprietary libraries.

Unless I'm misunderstanding, don't you mean third-party, not proprietary
(or is this a use of proprietary that I am not familiar with)?


pgp4tuwMQMHTp.pgp
Description: PGP signature
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library:

2013-08-21 Thread Alan Gauld

On 21/08/13 23:39, Chris Down wrote:

On 2013-08-21 23:30, Alan Gauld wrote:

It varies but in general programming terms is a collection of functions or
classes that can be reused by programmers. Most languages have a standard
library and a collection of additional proprietary libraries.


Unless I'm misunderstanding, don't you mean third-party, not proprietary
(or is this a use of proprietary that I am not familiar with)?


My dictionary says:

proprietary: protected by trademark or patent or copyright; made or 
produced or distributed by one having exclusive rights


So I mean a third party library, one whose copyright is separate
from the standard library. It could, of course, be copyright free
or public domain too, so third party may be a more accurate
term here.


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library of Module for Analyzing Answer Cards

2012-03-24 Thread bob gailer

  
  
Remember to always reply-all so a copy goes to the list.

On 3/24/2012 7:49 AM, Khalid Al-Ghamdi wrote:

  thanks a lot that was extremely helpful.

On Fri, Mar 23, 2012 at 3:58 AM, bob
  gailer bgai...@gmail.com
  wrote:
  

   On 3/22/2012 2:45 PM, Khalid Al-Ghamdi
wrote:

  Hi All,


I work in in academic testing environment and
  we employ expensive machines to scan answer sheets
  (the ones where you blacken the letter of the
  correct multiple choice answer). Anyway, I was
  thinking if there was a way we could use regular
  old scanners to scan the sheets than analyze the
  images to score the tests.

  


  
  This is not a Python solution - but www.cardiff-teleform.com/

offers a product called Teleform that does
  exactly what you want. I used it a while ago for a project
  where we scanned over 100,000 copies of 4 different forms.
  Worked like a charm.
  -- 
Bob Gailer
919-636-4239
Chapel Hill NC

  


  



-- 
Bob Gailer
919-636-4239
Chapel Hill NC
  

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library of Module for Analyzing Answer Cards

2012-03-23 Thread Emile van Sebille

On 3/22/2012 11:45 AM Khalid Al-Ghamdi said...

Hi All,

I work in in academic testing environment and we employ expensive
machines to scan answer sheets (the ones where you blacken the letter of
the correct multiple choice answer). Anyway, I was thinking if there was
a way we could use regular old scanners to scan the sheets than analyze
the images to score the tests.

Do you know any modules or libraries in python that can be helpful in
that? Also, what approach if any would you employ to tackle this project?



For quick production deployment, I'd check out Bob's suggestion.

If I were going to write a python based solution I'd start with PIL (see 
http://www.pythonware.com/products/pil/)


I haven't tried doing something quite as detailed as what you're 
describing, but I do have PIL doing image analysis, cropping and 
resizing on an automated basis in a production environment.


I think I'd examine the scanned image for a location marker, then from 
that and an answer template that provides the answer box locations, 
locate the answer box area for each question in turn and identify the 
filled in multiple choice response.


HTH,

Emile



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library of Module for Analyzing Answer Cards

2012-03-22 Thread bob gailer

On 3/22/2012 2:45 PM, Khalid Al-Ghamdi wrote:

Hi All,

I work in in academic testing environment and we employ expensive 
machines to scan answer sheets (the ones where you blacken the letter 
of the correct multiple choice answer). Anyway, I was thinking if 
there was a way we could use regular old scanners to scan the sheets 
than analyze the images to score the tests.


This is not a Python solution - but www.cardiff-*teleform*.com/ offers a 
product called Teleform that does exactly what you want. I used it a 
while ago for a project where we scanned over 100,000 copies of 4 
different forms. Worked like a charm.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library of Module for Analyzing Answer Cards better link

2012-03-22 Thread bob gailer

On 3/22/2012 2:45 PM, Khalid Al-Ghamdi wrote:

Hi All,

I work in in academic testing environment and we employ expensive 
machines to scan answer sheets (the ones where you blacken the letter 
of the correct multiple choice answer). Anyway, I was thinking if 
there was a way we could use regular old scanners to scan the sheets 
than analyze the images to score the tests.


This is not a Python solution - but 
http://www.cardiff.com/products/teleform/index.html offers a product 
called Teleform that does exactly what you want. I used it a while ago 
for a project where we scanned over 100,000 copies of 4 different forms. 
Worked like a charm.


--
Bob Gailer
919-636-4239
Chapel Hill NC

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library for files information

2009-03-23 Thread Alan Gauld


Shining Wisdom shininggg2...@gmail.com wrote

Hi, i want to write a script that copy file from a folder on my hdd to a 
usb thumb drive based on the time the file was created.


Just need help to find which library to google...


You don't need much. The os.path module will give you the creation time.
The time module may be needed too if you want to format the time
in your output..

For copying the files you can either use standard file operations or
the shutil module.

All of these are covered in my Using the OS topic in my tutorial


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/ 



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Library for Disk Usage (UNIX)

2008-03-26 Thread Chris Fuller
On Wednesday 26 March 2008 09:11, Tom Tucker wrote:
 Hello all. I'm looking for a builtin Python library capable of providing
 similar output to what the unix df command provides.  Obviously, I'm trying
 to avoid a system call if possible.  I'm looking for the following fields
 at a mimimum, total size, used, and /path. Suggestions?  I was looking at
 os.stat(/path)[WXYZ}, and os.path.getsize, but they are lacking.

 Thanks for the help,

 Tom

You need to know the size of the blocks that the filesystem uses.  Use the 
statvfs module and the os.statvfs function.

Cheers


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library to create venn diagrams?

2008-02-25 Thread John Fouhy
On 25/02/2008, Danny Navarro [EMAIL PROTECTED] wrote:
 Hi all,

  Does anyone know a Python library to generate Venn diagrams with more
  than 3 datasets? The area of the datasets and the intersections should
  be proportional to the quantity of data.

I don't ...

... also, how would you draw in two dimensions a Venn diagram of four
mutually-intersecting sets? I can't see how it is possible in
general..

-- 
John.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library to create venn diagrams?

2008-02-25 Thread Terry Carroll
On Tue, 26 Feb 2008, John Fouhy wrote:

 On 25/02/2008, Danny Navarro [EMAIL PROTECTED] wrote:
  Hi all,
 
   Does anyone know a Python library to generate Venn diagrams with more
   than 3 datasets? The area of the datasets and the intersections should
   be proportional to the quantity of data.
 
 I don't ...

I don't either, but...
 
 ... also, how would you draw in two dimensions a Venn diagram of four
 mutually-intersecting sets? I can't see how it is possible in
 general..

Although with most Venn diagrams, the enclosing shapes are generally 
circles, they don't need to be the same shapes, and you can have Venn 
diagrams with more than three sets.  Some examples here:

http://en.wikipedia.org/wiki/Venn_diagram

Also, a Venn diagram technically is a subset of the more general Euler
diagram.  The Venn diagram illustrates regions for all possible
combinations of intersections, e.g., for three sets ABC, A-only, B-only,
C-only, A+B only, A+C only, B+C only and A+B+C.  A Euler diagram can be
used where, for example, A intersects B but not C. More info at
http://en.wikipedia.org/wiki/Euler_diagram

I note the External Links section on the Venn diagram lists links to 
several tools to create Venn diagrams.  I don't know if any of  them are 
python, but if the OP is not limited to python-only solutions, they may 
help.

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] library to create venn diagrams?

2008-02-25 Thread Alan Gauld

Terry Carroll [EMAIL PROTECTED] wrote

 Also, a Venn diagram technically is a subset of the more general 
 Euler
 diagram.  The Venn diagram illustrates regions for all possible
 combinations of intersections, e.g., for three sets ABC, A-only, 
 B-only,
 C-only, A+B only, A+C only, B+C only and A+B+C.  A Euler diagram can 
 be
 used where, for example, A intersects B but not C. More info at
 http://en.wikipedia.org/wiki/Euler_diagram

Hmm, thats an interesting link.

I studied math through to 5th year at university using sets all the 
way
and never heard the term Euler diagram used, they were always
just called Venn diagrams.

You learn something new every day! :-)

Alan G. 


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor