def cDownload():
    
    print("Enter package name ")
    sName=input
    print("Enter download location ")
    sLocation=input
    command = "wget http://aur.archlinux.org/packages/" + sName + "/" + sName + ".tar.gz -O" + sLocation + "/" + sName + ".tar.gz"
    os.system(command)

I get
TypeError: Can't convert 'builtin_function_or_method' object to str implicitly

Dani AI

Generated

Short answer: was right — your variables ended up holding the input function itself because you assigned input instead of calling it. That makes Python try to concatenate a function object with strings, which raises a TypeError. Two extra points to keep in mind: in Python 2 input() evaluates the typed expression (use raw_input() to get a string), while in Python 3 input() already returns a string.

Here’s a small, safe pattern that works across Py2/Py3 for reading the two values and normalizing them (does not repeat the original snippet):

try:
    input_fn = raw_input
except NameError:
    input_fn = input

name = input_fn("Package name: ").strip()
location = input_fn("Download location: ").strip()

Avoid building a shell command string with untrusted input (that opens you to quoting bugs and shell injection). Prefer a library download or calling an external tool with a list of arguments. Example using the standard library (replace the placeholder base URL as appropriate):

import os
try:
    from urllib.request import urlretrieve
except ImportError:
    from urllib import urlretrieve

filename = name + ".tar.gz"
dest_dir = os.path.expanduser(location)
if not os.path.isdir(dest_dir):
    os.makedirs(dest_dir)
dest_path = os.path.join(dest_dir, filename)

url = "/".join([base_url.rstrip('/'), name, filename])
urlretrieve(url, dest_path)

Troubleshooting tips: if you still see a TypeError, print repr(name) and type(name) to confirm the variable is a string. If you must shell out, use subprocess.check_call(['wget', url, '-O', dest_path]) (argument list, not a single concatenated string). Finally, if running old Python 2 code, switch to raw_input() to avoid evaluation surprises.

Recommended Answers

All 3 Replies

I have tried this in other languages such as C++ and ruby and it works just fine.

You need to call the function "input"
So it'd look like:

input()
commented: sharp eye +15

Oops. I missed those. I noticed the ones in cSearch I did but failed to notice those. Thanks for pointing that out. Sorry, I am just now trying to learn.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.