Automating RealTerm with Python
I am currently in the process of creating a script to automate RealTerm. I need to send a binary file and have the Winsock setting set to "Raw". RealTerms documentation indicates that I need an integer 0 or 1 for this setting but I am receiving a "object has no attribute" "Winsock".
RT.Winsock = 0
is what I currently have it set at. This this is the error message I get. '<win32com.gen_py.Realterm Library.IRealtermIntf instance at 0x1826368502752>' object has no attribute 'Winsock'
Could this be a bug in the program?
I have also tried RT.Winsock = ("0")
and that returned the same error but that sets it as a string and not integer.
Any thoughts on how it should be set or what I'm doing wrong? Here is my full error below.
Exception has occurred: AttributeError '<win32com.gen_py.Realterm Library.IRealtermIntf instance at 0x2390257155040>' object has no attribute 'Winsock'
During handling of the above exception, another exception occurred:
File "C:\NetworkUpdater\NUP\NUPv1.0.py", line 13, in module RT.Winsock = 0
Edit: Added code below
RT = DispatchEx("Realterm.RealtermIntf")
RT.Visible = True
RT.Caption = "Realterm Controlled from Python"
RT.SelectTabSheet("Port")
RT.Winsock = 0
do you know?
how many words do you know
See also questions close to this topic
-
Python File Tagging System does not retrieve nested dictionaries in dictionary
I am building a file tagging system using Python. The idea is simple. Given a directory of files (and files within subdirectories), I want to filter them out using a filter input and tag those files with a word or a phrase.
If I got the following contents in my current directory:
data/ budget.xls world_building_budget.txt a.txt b.exe hello_world.dat world_builder.spec
and I execute the following command in the shell:
py -3 tag_tool.py -filter=world -tag="World-Building Tool"
My output will be:
These files were tagged with "World-Building Tool": data/ world_building_budget.txt hello_world.dat world_builder.spec
My current output isn't exactly like this but basically, I am converting all files and files within subdirectories into a single dictionary like this:
def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree
Right now, my dictionary looks like this:
key:''
.In the following function, I am turning the empty values
''
into empty lists (to hold my tags):def empty_str_to_list(d): for k,v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v)
When I run my entire code, this is my output:
hello_world.dat ['World-Building Tool'] world_builder.spec ['World-Building Tool']
But it does not see
data/world_building_budget.txt
. This is the full dictionary:{'data': {'world_building_budget.txt': []}, 'a.txt': [], 'hello_world.dat': [], 'b.exe': [], 'world_builder.spec': []}
This is my full code:
import os, argparse def fs_tree_to_dict(path_): file_token = '' for root, dirs, files in os.walk(path_): tree = {d: fs_tree_to_dict(os.path.join(root, d)) for d in dirs} tree.update({f: file_token for f in files}) return tree def empty_str_to_list(d): for k, v in d.items(): if v == '': d[k] = [] elif isinstance(v, dict): empty_str_to_list(v) parser = argparse.ArgumentParser(description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument("--filter", action="store", help="keyword to filter files") parser.add_argument("--tag", action="store", help="a tag phrase to attach to a file") parser.add_argument("--get_tagged", action="store", help="retrieve files matching an existing tag") args = parser.parse_args() filter = args.filter tag = args.tag get_tagged = args.get_tagged current_dir = os.getcwd() files_dict = fs_tree_to_dict(current_dir) empty_str_to_list(files_dict) for k, v in files_dict.items(): if filter in k: if v == []: v.append(tag) print(k, v) elif isinstance(v, dict): empty_str_to_list(v) if get_tagged in v: print(k, v)
-
Actaully i am working on a project and in it, it is showing no module name pip_internal plz help me for the same. I am using pycharm(conda interpreter
File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\Scripts\pip.exe\__main__.py", line 4, in <module> File "C:\Users\pjain\AppData\Local\Programs\Python\Python310\lib\site-packages\pip\_internal\__init__.py", line 4, in <module> from pip_internal.utils import _log
I am using pycharm with conda interpreter.
-
Looping the function if the input is not string
I'm new to python (first of all) I have a homework to do a function about checking if an item exists in a dictionary or not.
inventory = {"apple" : 50, "orange" : 50, "pineapple" : 70, "strawberry" : 30} def check_item(): x = input("Enter the fruit's name: ") if not x.isalpha(): print("Error! You need to type the name of the fruit") elif x in inventory: print("Fruit found:", x) print("Inventory available:", inventory[x],"KG") else: print("Fruit not found") check_item()
I want the function to loop again only if the input written is not string. I've tried to type return Under print("Error! You need to type the name of the fruit") but didn't work. Help
-
How to read the RemoteAddress of client in WDK (windows driver) socket (wsk.h)?
I want to read the remote address of the client in a windows driver socket.
I imported Wsk.h, created my socket, accept the connection via WskAccept. I want to debug log the remote address ([out, optional] PSOCKADDR RemoteAddress) in a human-readable ipv4 address.
In winsock2 there is InetNtop and WSAAddressToStringA. What can I use in Wsk.h as an alternative to these?
-
How can I receive a message on client by socket?
I'm working on a C++ project that use sockets to transfer the message, I've done the sending part which looks like this(IDK if it's correct, if no please let me know what should I do)
void CFinalProjectKeithDlg::OnBnClickedSend() { CString ChatMessage; SetDlgItemText(IDC_EDIT_CHAT, ChatMessage); //const char* pkt = "Message to be sent"; const char* srcIP = "127.0.0.1"; const char* destIP = "127.0.0.1"; sockaddr_in dest; sockaddr_in local; WSAData data; WSAStartup(MAKEWORD(2, 2), &data); local.sin_family = AF_INET; inet_pton(AF_INET, srcIP, &local.sin_addr.s_addr); local.sin_port = htons(0); dest.sin_family = AF_INET; inet_pton(AF_INET, destIP, &dest.sin_addr.s_addr); dest.sin_port = htons(3514); SOCKET s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); bind(s, (sockaddr*)&local, sizeof(local)); sendto(s, ChatMessage, strlen(ChatMessage), 0, (sockaddr*)&dest, sizeof(dest)); closesocket(s); WSACleanup(); }
Now I'll need to code a receiving part that receives the message. IDK where to start, this is my first real programming project. I really don't know how to start.
-
AttributeError: Open.Close Error while merging pptx presentation
I am trying to use the function proposed by @Zeynel which is the following function:
def mergePresentations(inputFileNames, outputFileName): Application = win32com.client.Dispatch("PowerPoint.Application") outputPresentation = Application.Presentations.Add() outputPresentation.SaveAs(outputFileName) for file in inputFileNames: currentPresentation = Application.Presentations.Open(file) currentPresentation.Slides.Range(range(1, currentPresentation.Slides.Count + 1)).copy() Application.Presentations(outputFileName).Windows(1).Activate() outputPresentation.Application.CommandBars.ExecuteMso("PasteSourceFormatting") currentPresentation.Close() outputPresentation.save() outputPresentation.close() Application.Quit()
However I keep getting the following error: AttributeError: Open.Close Where the ppt file Does not close by the win32com library and stops the whole merging process. Any idea about the cause of the problem and how to solve?
-
Iterating through a list within dictionary in a for loop
I am trying to store all mails from outlook in a database. for that i need to iterate through every folder i have in outlook. I am using win32com.client for that. I created a dictionary with every name of the postbox as a key and all of the folders as a list with values.
postbox_and_folders = {} folder_of_postbox = [] for postbox in postboxes: for idx, folder in enumerate(mapi.Folders(postbox).Folders): folder_of_postbox.append(str(folder)) postbox_and_folders[postbox] = folder_of_postbox if str(folder) == 'Archive': folder_of_postbox = [] print(postbox_and_folders)
The output looks like this:
{'@VPC': ['Calendar', 'Contacts', 'Conversation Action Settings', 'Conversation History', 'Deleted Items', 'Drafts', 'Einstellungen für QuickSteps', 'ExternalContacts', 'Files', 'Inbox', 'Journal', 'Junk Email', 'Notes', 'Outbox', 'PersonMetadata', 'Sent Items', 'Social Activity Notifications', 'Sync Issues', 'Tasks', 'Yammer Root', 'Archive'], '@FCC': ['Calendar', 'Contacts', 'Conversation Action Settings', 'Conversation History', ...] which is exactly how it should look.
Now is my goal to go through each postbox and their respective folders to store the body of the messages in a database.
I know I have to use mapi.Folders but am not able to make it work with this dictionary. How do I iterate through every folder with this dictionary?
I just have to put the dictionary in this function and I feel like I'm pretty close to it.
for key, value in postbox_and_folders.items(): messages = mapi.Folders(str(key)).Folders(value[i]).Items for message in list(messages)[:10]: print(message.Body)
-
pywin32: The shortcut pathname must end with .lnk or .url
I have a python script that helps me to manage shortcuts to my various projects by creating directories and shortcut files. I have been using pywin32 and python 10 for the past few months and it has worked fine, but recently I've come across an error that doesn't seem to apply to my situation and wasn't there before. When I noticed this, I had just switched editors from VSCode to PyCharm and made some formatting changes, though neither of those actions seems related to this problem, especially since I'm running the file through command prompt rather than either IDE (though the error also occurs when I run through the IDE).
My program will generate a file path that looks like this:
C:\\Users\<User>\Desktop\Local Projects\Shortcuts\Folder\test.lnk
and I will get an error with this message every time:
File "C:\Users\<User>\OneDrive - <Organization>\Desktop\Local Projects\create new.py", line 594, in <module> shortcut = shell.CreateShortCut(shortcut_path) File "<COMObject WScript.Shell>", line 2, in CreateShortCut pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'WshShell.CreateShortcut', 'The shortcut pathname must end with .lnk or .url.', None, 0, -2147352567), None)
The error message seems to indicate that the pathname does not end in ".lnk" or ".url", but I have confirmed that the variable does end in ".lnk" when this error occurs. I've attempted to reinstall the package multiple times, to no avail.
Something to note is that my desktop folder ("C:\Users\\Desktop") is actually a junction that I configured to redirect to the OneDrive path. This has not been a problem with the script before.