[Tutor] Data Structures printing and Python Package creation

Alex Kleider akleider at sonic.net
Sat Feb 3 14:39:11 EST 2018


On 2018-02-03 11:20, Bob Gailer wrote:
> On Feb 3, 2018 2:09 PM, "Daniel Bosah" <dbosah at buffalo.edu> wrote:
>> 
>> I'm in a research group for school, and my first task is to learn how 
>> to
>> make a Python package and to learn how to print out all types of data
>> structures. Are there resources I can be pointed to to help me out.
> 
> https://python-packaging.readthedocs.io/en/latest/
> 
> I got that using Google search. Hint hint?
> 
> All types is a bit vague. I suggest you take one type at a time.
> 
> Very often it is sufficient to print the object using, as you might 
> guess,
> the print function.
> 
> Also Google python prettyprint and python formatting.
> 
> Let us know how it goes and please ask more questions.

Here's another to consider: 
https://packaging.python.org/tutorials/distributing-packages/

As for printing out data structures: I assume you mean to present a 
textual representation of specific instances. If the instances are of 
built in types, simply print:
>>> print(myvar)     # as suggested by Bob above
If it is an instance of a class you've created yourself, then to get 
anything useful you'll have had to declare a __str__ method within that 
class. The method should return (as a string) what you want print to 
show.

...at least that's my understanding.



More information about the Tutor mailing list