CITGuru / PyInquirer

A Python module for common interactive command line user interfaces
MIT License
1.91k stars 236 forks source link

AssertionError #56

Closed bluedaze closed 5 years ago

bluedaze commented 5 years ago
Traceback (most recent call last):
  File "/data/Python/pyinquirertest.py", line 46, in <module>
    answers = prompt(questions, style=custom_style_2)
  File "/usr/lib/python3.7/site-packages/PyInquirer/prompt.py", line 75, in prompt
    eventloop=eventloop)
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/shortcuts.py", line 576, in run_application
    output=create_output(true_color=true_color))
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/shortcuts.py", line 126, in create_output
    ansi_colors_only=ansi_colors_only, term=term)
  File "/usr/lib/python3.7/site-packages/prompt_toolkit/terminal/vt100_output.py", line 424, in from_pty
    assert stdout.isatty()
AssertionError

For whatever reason I keep getting this error whenever I try to run a script. I'm fairly new to programming and python, so forgive me if this is a newbie error. I have run numerous examples that were provided, and I can't get any of them to work.

As a reference here is the latest code I tried to write that threw the error above. I am currently running Python 3.7.2.


# -*- coding: utf-8 -*-
"""
* Input prompt example
* run example by writing `python example/input.py` in your console
"""
from __future__ import print_function, unicode_literals
import regex
from pprint import pprint

from PyInquirer import style_from_dict, Token, prompt
from PyInquirer import Validator, ValidationError

from examples import custom_style_2

class PhoneNumberValidator(Validator):
    def validate(self, document):
        ok = regex.match('^([01]{1})?[-.\s]?\(?(\d{3})\)?[-.\s]?(\d{3})[-.\s]?(\d{4})\s?((?:#|ext\.?\s?|x\.?\s?){1}(?:\d+)?)?$', document.text)
        if not ok:
            raise ValidationError(
                message='Please enter a valid phone number',
                cursor_position=len(document.text))  # Move cursor to end

questions = [
    {
        'type': 'input',
        'name': 'first_name',
        'message': 'What\'s your first name',
    },
    {
        'type': 'input',
        'name': 'last_name',
        'message': 'What\'s your last name',
        'default': lambda answers: 'Smith' if answers['first_name'] == 'Dave' else 'Doe',
        'validate': lambda val: val == 'Doe' or 'is your last name Doe?'
    },
    {
        'type': 'input',
        'name': 'phone',
        'message': 'What\'s your phone number',
        'validate': PhoneNumberValidator
    }
]

answers = prompt(questions, style=custom_style_2)
pprint(answers)

Any help would be greatly appreciated.

Thank you, Sean

bluedaze commented 5 years ago

Welp, disregard. It appears to be working perfectly normally. I ran it in the terminal, instead of the python console. Makes sense, though. Kinda wish it would work in the Python console to make my life easier though. Sorry about the trouble, and thanks for the hard work!

CITGuru commented 5 years ago

Oh cool.

spotlesscoder commented 3 years ago

Has anyone been able to use it in debugging mode in PyCharm?

TobiasKiehnlein commented 3 years ago

Has anyone been able to use it in debugging mode in PyCharm?

I actually did.

On the top right you should have a drop down with all your run configurations. Select the top option 'Edit Configurations...'. And select your configuration on the left.

It should look like this now: image

Make sure to check the option 'Emulate terminal in output console'. After that everything worked as expected.