My question is very novice level, sorry. I use pycharm but am open to other better suggestions according to my problem.
I would like to execute the code in the interpreter itself, but according to the book I practice, all the examples as one that I will post next, follow the methodology different from the one I was adapted, it may be on my part: Lack of custom; or the book has this proposal exactly as challenge; or I'm doing poorly on reading. What bothers me and hinders my learning is the code being described in one file and the call of the methods etc ... made in another, in the terminal (> > >).
So at any moment I'm forced to copy the code to the terminal.
- Example taken from the book Python Fluent (Luciano Ramalho).
import collections
from random import choice
Card = collections.namedtuple('Card',['rank', 'suit'])
class FrenchDeck:
ranks = [str(n) for n in range (2, 11)] + list ('JQKA')
suits = 'spades diamonds clubs hearts'.split()
suits_values = dict(spades=3, hearts=2, diamonds=1, clubs=0)
def __init__(self):
self._cards = [Card(rank, suit) for suit in self.suits
for rank in self.ranks]
def __len__(self):
return len(self._cards)
def __getitem__(self, position):
return self._cards[position]
Here is how code is called to run;
Running:
>>> beer_dark = Card('7', 'diamonds')
>>> beer_card
Card(rank='7', suit='diamonds')
>>> deck = FrenchDeck()
>>> len(deck)
52
As the code grows, it sometimes adds settings to the terminal. Personally, let me know if there is a practical way or I will have to adapt the code, incrementing parameters where there is not so that I can execute it at once in the interpreter.