How do I print and input at the same line in Python 3.4? - user-input

I just do not understand how to put the print function and input function at the same line.
In python 3.4, I wrote it like this:
Hello = input("Hello adventurer, what is your name?")
print (Hello," ","-"," ",input("are you a warrior,wizard or programmer?"))
But, it came out like this....
Hello adventurer, what is your name?
jake
are you a warrior,wizard or programmer?
warrior
jake - warrior
if I want answer to be like this on the bottom line, how should I do it?:
Hello adventurer, what is your name?
Joe
Joe - are you a Warrior, Wizard or Programmer?
Wizard

i think you already found the answer, but it might be useful for someone else.
To achieve your goal you need to use print() without end of the line symbol. you can do this by entering :
person = input('Enter your name: ')
print('Hello ', person, '!', sep='', end='')
input(' - are you a Warrior, Wizard or Programmer? :')
To achieve better look and fine text adjustment, you can use "sep" as well.

In Python 2.7, you can do something like this:
>>> person = input("Hello adventurer, what is your name?\n")
Hello adventurer, what is your name?
"Joe"
>>> interest = input("%s - are you a warrior, wizard or programmer?\n" % person)
Joe - are you a warrior, wizard or programmer?
"Wizard"
>>> print interest
Wizard
You might be able to achieve the same results with just some more modifications.

Related

How to escape the . when using dot notation commandline arguments

I want to pass in a config like:
foo
blah.bar: blah.bar
another.thing: some.thing
And I want to do this on the commmandline, osmething like:
python my_script.py foo.blah.bar=blah.bar foo.another.thing=some.thing
Obviously, this would give me instead:
foo
blah
bar: blah.bar
another
thing: some.thing
... which is not what I want. How can I escape any periods (.) when using dot notation with omegaconf.OmegaConf.from_cli() ?
Based on the comment here, I think you could do something like:
python my_script.py foo[blah.bar]=blah.bar foo[another.thing]=some.thing
But I've never used omegaconf, so please don't beat me up for guessing :)
This is not supported.
You can file a feature request but it's not going to be high pri. I suggest that you use a different separator in your keys.

Write x y times to text file

I was looking for the cleanest way to accomplish writing $2 to a text file the amount of times specified. I'm sure this is possible and i will provide and example to what I am looking for...
on *:text:*write*:?: { write test.txt $2 "$3 times"}
so, for an example, the user would type
write Hello 3
this would write hello on 3 lines to test.txt, the contents should be as following in test.txt
Hello
Hello
Hello
Thank you!
The way I would have approached this is with a timer, I don't really know an easier way. Anyways, I posted this looking for the CORRECT way to do this or at least the most clean.
if you want an instant answer instead of waiting timers, you can use while loops
on *:text:*write*:?: {
var %x = 1
while (%x <= $$3) {
write test.txt $2
inc %x
}
}

perl - search multi-line string for match of any of a list of strings

I have a list of bug identifiers.
For each bugid in this buglist, I run an external command to get the history of the bug as a multi-line string:
$buginfo = `dumpbug $bugid`;
$buginfo looks something like this (greatly simplified):
04/04/2014 dog created
04/04/2014 cat manager
04/04/2014 moose assigner
04/04/2014 moose engineer
04/05/2014 moose resolved
04/06/2014 rabbit verified
Now I want to see if any of (fox, aardvark, emu, rabbit) has ever had anything to do with this bug.
I would like to stop searching through $bugid on the first match of any user in my list.
I will be searching the buginfo from each of the bugids in my buglist for the same users.
I am also limited to features of perl 5.8
print "$1 was involved in bug $bugid.\n" if $buginfo =~ /\b(fox|aardvark|emu|rabbit)\b/;

Perl - finding multiple substrings in a variable?

I'm very new to Perl and I've been using this site for a few years looking for answers to questions I've had regarding other projects I've been working on but I can't seem to find the answer to this one..
My script receives a HTTP response with data that I need to strip down to parse the correct information.
So far, I have this for the substring..
my $output = substr ($content, index($content, 'Down'), index($content, '>'));
This seems to be doing what it's supposed to be.. finding the word 'Down' and then substringing it up until it finds a >.
However, the string 'Down' can appear many times within the response and this stops looking after it finds the first example of this.
How would I go about getting the substring to be recursive?
Thanks for your help :)
One way like this:
my $x="aa Down aaa > bb Down bbb > cc Down ccc >";
while ($x =~/(Down[^>]+>)/g){
print $1;
}
Another solution,without iteration and just storing what is down.
use Data::Dumper;
my $x="aa Down aaa > bb Down bbb > cc Down ccc >";
my #downs = $x =~ m!Down([^>]+)>!gis;
print Dumper(\#downs);

Basic Input from the Command Line in Rebol

I am currently in the process of learning Rebol.
In other languages I know, I can read input from the command line, for example in Java:
Scanner sc = new Scanner(System.in)
sc.nextLine();
In C#
Console.ReadLine();
In C
scanf("%s", s);
I was wondering how one would accomplish the same thing in Rebol.
You can use the input command to ask for input at the console.
>> name: input
Joe
== "Joe"
The ask function complements input by printing a string prior to requesting input:
age: ask "How old are you? "
It also has a /hide refinement to conceal input:
pass: ask/hide "Enter your password: "
At this time, /hide is not implemented in Rebol 3 alphas
A longer answer (and for intermediate-level at least) would include monitoring the system/ports/input port (you can do source input for how this is done for you)—this can be used in cases where input doesn't originate at the console (such as shell, CGI).