<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Python: How to import files as modules?]]></title><description><![CDATA[<p dir="auto">Hello everybody,</p>
<p dir="auto">I'm new to this forum, so please bear with me in case my questions are hardly noob ish. I tried my best to consult the docs and the search first, but still I do have this question:</p>
<p dir="auto">Right now, I'm working on a script that hit the 600 lines mark, so I thought it's a good idea to create different files and use import to use these files as modules. But somehow C4D python refuses to find the file and use these files as modules. As soon as I deactivate the VSC C4D bridge, the import works (at least this is what the VSC console is telling me).<br />
I've set up an Environment Variable to my script repo with the hope this would fix it, but without any luck.</p>
<p dir="auto">Is this bad practice for a script? Shall I turn it into a plugin to have this as an option?</p>
]]></description><link>http://developers.maxon.net/forum/topic/15298/python-how-to-import-files-as-modules</link><generator>RSS for Node</generator><lastBuildDate>Fri, 15 May 2026 13:07:56 GMT</lastBuildDate><atom:link href="http://developers.maxon.net/forum/topic/15298.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 19 Dec 2023 17:34:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Python: How to import files as modules? on Thu, 21 Dec 2023 16:40:20 GMT]]></title><description><![CDATA[<p dir="auto">Hi <a class="plugin-mentions-user plugin-mentions-a" href="/forum/user/gaschka">@<bdi>gaschka</bdi></a>,</p>
<p dir="auto">In your next postings please provide more detailed description of your question. In this case you're lacking information about the file structure you're using, the code that performs the import, the information on how and what have you set the environment variable for.</p>
<p dir="auto">Regarding your question, when splitting python code into separate pieces one usually uses the concept of <a href="https://docs.python.org/3/tutorial/modules.html#packages" target="_blank" rel="noopener noreferrer nofollow ugc">packages</a> rather than raw files. Hence, your question relates to local modules you'd like to use in your script. Please, have a look at the <a href="https://developers.maxon.net/docs/py/2024_0_0a/manuals/manual_py_libraries.html" target="_blank" rel="noopener noreferrer nofollow ugc">Python Libraries Manual</a> especially the last section about the <a href="https://developers.maxon.net/docs/py/2024_0_0a/manuals/manual_py_libraries.html#local-plugin-search-paths" target="_blank" rel="noopener noreferrer nofollow ugc">Local Plugin Search Paths</a>.</p>
<p dir="auto">Another point of interest for you would be a utility function <a href="https://developers.maxon.net/docs/py/2024_0_0a/modules/maxon_generated/mxutils/mxutils.LocalImportPath.html#module-mxutils.LocalImportPath" target="_blank" rel="noopener noreferrer nofollow ugc">LocalImportPath</a> that simplifies the process of importing packages.</p>
<p dir="auto">If you have any further questions, please let me know and provide a code sketch that showcases your issue.</p>
<p dir="auto">Cheers,<br />
Ilia</p>
]]></description><link>http://developers.maxon.net/forum/post/73404</link><guid isPermaLink="true">http://developers.maxon.net/forum/post/73404</guid><dc:creator><![CDATA[i_mazlov]]></dc:creator><pubDate>Thu, 21 Dec 2023 16:40:20 GMT</pubDate></item></channel></rss>