another python file how could I an an input which would be the martketHashName and it…
- User
another python file how could I an an input which would be the martketHashName and it would then find the item in the csv and print the other details
- Assistant
You can achieve this by using Python's built-in
csvmodule to read the CSV file and look for the matchingmarketHashName. Here's a sample code:import csv def find_item_in_csv(market_hash_name, file_path='yourfile.csv'): with open(file_path, newline='', encoding='utf-8') as csvfile: reader = csv.DictReader(csvfile) for row in reader: if row['marketHashName'] == market_hash_name: print('Details for item {}:'.format(market_hash_name)) for key, value in row.items(): if key != 'marketHashName': print(' {}: {}'.format(key, value)) return print('Item with marketHashName "{}" not found.'.format(market_hash_name)) market_hash_name = input('Enter the marketHashName: ').strip() find_item_in_csv(market_hash_name)Replace 'yourfile.csv' with the path to your actual CSV file, and ensure the correct field name for the 'marketHashName' column.
This code defines a function , which accepts a parameter and an optional parameter. The function reads the CSV file, checks each row for a match on the field, and print the details for that row if found. If the item is not found, it will print a message indicating this.