• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python py3compat.getcwd函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中spyder.py3compat.getcwd函数的典型用法代码示例。如果您正苦于以下问题:Python getcwd函数的具体用法?Python getcwd怎么用?Python getcwd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了getcwd函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: open_project

    def open_project(self, path=None, restart_consoles=True,
                     save_previous_files=True):
        """Open the project located in `path`"""
        if path is None:
            basedir = get_home_dir()
            path = getexistingdirectory(parent=self,
                                        caption=_("Open project"),
                                        basedir=basedir)
            if not self.is_valid_project(path):
                if path:
                    QMessageBox.critical(self, _('Error'),
                                _("<b>%s</b> is not a Spyder project!") % path)
                return
            else:
                self.add_to_recent(path)

        # A project was not open before
        if self.current_active_project is None:
            if save_previous_files:
                self.editor.save_open_files()
            self.editor.set_option('last_working_dir', getcwd())
            self.show_explorer()
        else: # we are switching projects
            self.set_project_filenames(self.editor.get_open_filenames())

        self.current_active_project = EmptyProject(path)
        self.latest_project = EmptyProject(path)
        self.set_option('current_project_path', self.get_active_project_path())
        self.setup_menu_actions()
        self.sig_project_loaded.emit(path)
        self.pythonpath_changed.emit()
        if restart_consoles:
            self.restart_consoles()
开发者ID:rlaverde,项目名称:spyder,代码行数:33,代码来源:projects.py


示例2: compare

 def compare(self):
     filename, _selfilter = getopenfilename(self, _("Select script to compare"),
                                            getcwd(), _("Profiler result")+" (*.Result)")
     if filename:
         self.datatree.compare(filename)
         self.show_data()
         self.clear_button.setEnabled(True)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:7,代码来源:profilergui.py


示例3: select_file

 def select_file(self):
     self.redirect_stdio.emit(False)
     filename = getexistingdirectory(
         self, _("Select directory"), getcwd())
     self.redirect_stdio.emit(False)
     if filename:
         self.analyze(filename)
开发者ID:spyder-ide,项目名称:spyder.unittest,代码行数:7,代码来源:unittestinggui.py


示例4: select_file

 def select_file(self):
     self.redirect_stdio.emit(False)
     filename, _selfilter = getopenfilename(self, _("Select Python file"),
                        getcwd(), _("Python files")+" (*.py ; *.pyw)")
     self.redirect_stdio.emit(True)
     if filename:
         self.analyze(filename)
开发者ID:rlaverde,项目名称:spyder,代码行数:7,代码来源:pylintgui.py


示例5: save_data

 def save_data(self, filename=None):
     """Save data"""
     if filename is None:
         filename = self.filename
         if filename is None:
             filename = getcwd()
         filename, _selfilter = getsavefilename(self, _("Save data"),
                                                filename,
                                                iofunctions.save_filters)
         if filename:
             self.filename = filename
         else:
             return False
     QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
     QApplication.processEvents()
     if self.is_internal_shell:
         wsfilter = self.get_internal_shell_filter('picklable',
                                                   check_all=True)
         namespace = wsfilter(self.shellwidget.interpreter.namespace).copy()
         error_message = iofunctions.save(namespace, filename)
     else:
         settings = self.get_view_settings()
         error_message = monitor_save_globals(self._get_sock(),
                                              settings, filename)
     QApplication.restoreOverrideCursor()
     QApplication.processEvents()
     if error_message is not None:
         QMessageBox.critical(self, _("Save data"),
                         _("<b>Unable to save current workspace</b>"
                           "<br><br>Error message:<br>%s") % error_message)
     self.save_button.setEnabled(self.filename is not None)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:31,代码来源:namespacebrowser.py


示例6: save_data

    def save_data(self, filename=None):
        """Save data"""
        if filename is None:
            filename = self.filename
            if filename is None:
                filename = getcwd()
            filename, _selfilter = getsavefilename(self, _("Save data"),
                                                   filename,
                                                   iofunctions.save_filters)
            if filename:
                self.filename = filename
            else:
                return False
        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        QApplication.processEvents()

        error_message = self.shellwidget.save_namespace(self.filename)
        self.shellwidget._kernel_reply = None

        QApplication.restoreOverrideCursor()
        QApplication.processEvents()
        if error_message is not None:
            QMessageBox.critical(self, _("Save data"),
                            _("<b>Unable to save current workspace</b>"
                              "<br><br>Error message:<br>%s") % error_message)
        self.save_button.setEnabled(self.filename is not None)
开发者ID:rlaverde,项目名称:spyder,代码行数:26,代码来源:namespacebrowser.py


示例7: open_interpreter

 def open_interpreter(self, wdir=None):
     """Open interpreter"""
     if not wdir:
         wdir = getcwd()
     self.visibility_changed(True)
     self.start(fname=None, wdir=to_text_string(wdir), args='',
                interact=True, debug=False, python=True)
开发者ID:jitseniesen,项目名称:spyder,代码行数:7,代码来源:externalconsole.py


示例8: save_data

 def save_data(self):
     """Save data"""
     title = _( "Save profiler result")
     filename, _selfilter = getsavefilename(self, title,
                                            getcwd(),
                                            _("Profiler result")+" (*.Result)")
     if filename:
         self.datatree.save_data(filename)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:8,代码来源:profilergui.py


示例9: select_directory

 def select_directory(self):
     """Select directory"""
     self.redirect_stdio.emit(False)
     directory = getexistingdirectory(self.main, _("Select directory"),
                                      getcwd())
     if directory:
         self.chdir(directory)
     self.redirect_stdio.emit(True)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:8,代码来源:workingdirectory.py


示例10: select_directory

 def select_directory(self):
     """Select directory"""
     basedir = to_text_string(self.wd_edit.text())
     if not osp.isdir(basedir):
         basedir = getcwd()
     directory = getexistingdirectory(self, _("Select directory"), basedir)
     if directory:
         self.wd_edit.setText(directory)
         self.wd_cb.setChecked(True)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:9,代码来源:runconfig.py


示例11: refresh_plugin

 def refresh_plugin(self):
     """Refresh widget"""
     curdir = getcwd()
     self.pathedit.add_text(curdir)
     self.save_wdhistory()
     self.set_previous_enabled.emit(
                          self.histindex is not None and self.histindex > 0)
     self.set_next_enabled.emit(self.histindex is not None and \
                                self.histindex < len(self.history)-1)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:9,代码来源:workingdirectory.py


示例12: run_script

 def run_script(self):
     """Run a Python script"""
     self.redirect_stdio.emit(False)
     filename, _selfilter = getopenfilename(self, _("Run Python script"),
             getcwd(), _("Python scripts")+" (*.py ; *.pyw ; *.ipy)")
     self.redirect_stdio.emit(True)
     if filename:
         self.start(fname=filename, wdir=None, args='',
                    interact=False, debug=False)
开发者ID:jitseniesen,项目名称:spyder,代码行数:9,代码来源:externalconsole.py


示例13: select_directory

 def select_directory(self):
     """Display dialog for user to select working directory."""
     basedir = to_text_string(self.wdir_lineedit.text())
     if not osp.isdir(basedir):
         basedir = getcwd()
     title = _("Select directory")
     directory = getexistingdirectory(self, title, basedir)
     if directory:
         self.wdir_lineedit.setText(directory)
开发者ID:jitseniesen,项目名称:spyder.unittest,代码行数:9,代码来源:configdialog.py


示例14: getcwd_or_home

def getcwd_or_home():
    """Safe version of getcwd that will fallback to home user dir.

    This will catch the error raised when the current working directory
    was removed for an external program.
    """
    try:
        return getcwd()
    except OSError:
        logger.debug("WARNING: Current working directory was deleted, "
                     "falling back to home dirertory")
        return get_home_dir()
开发者ID:burrbull,项目名称:spyder,代码行数:12,代码来源:misc.py


示例15: set

 def set(self, options):
     self.args = options.get('args', '')
     self.args_enabled = options.get('args/enabled', False)
     if CONF.get('run', WDIR_USE_FIXED_DIR_OPTION, False):
         default_wdir = CONF.get('run', WDIR_FIXED_DIR_OPTION, getcwd())
         self.wdir = options.get('workdir', default_wdir)
         self.wdir_enabled = True
     else:
         self.wdir = options.get('workdir', getcwd())
         self.wdir_enabled = options.get('workdir/enabled', False)
     self.current = options.get('current',
                        CONF.get('run', CURRENT_INTERPRETER_OPTION, True))
     self.systerm = options.get('systerm',
                        CONF.get('run', SYSTERM_INTERPRETER_OPTION, False))
     self.interact = options.get('interact',
                        CONF.get('run', 'interact', False))
     self.show_kill_warning = options.get('show_kill_warning', 
                        CONF.get('run', 'show_kill_warning', False))
     self.post_mortem = options.get('post_mortem',
                        CONF.get('run', 'post_mortem', False))
     self.python_args = options.get('python_args', '')
     self.python_args_enabled = options.get('python_args/enabled', False)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:22,代码来源:runconfig.py


示例16: update_default_wdir

    def update_default_wdir(self):
        """
        Update default working dir for running unit tests.

        The default working dir for running unit tests is set to the project
        directory if a project is open, or the current working directory if no
        project is opened. This function is called whenever this directory may
        change.
        """
        wdir = self.main.projects.get_active_project_path()
        if not wdir:  # if no project opened
            wdir = getcwd()
        self.unittestwidget.default_wdir = wdir
开发者ID:jitseniesen,项目名称:spyder.unittest,代码行数:13,代码来源:unittestplugin.py


示例17: refresh

 def refresh(self, new_path=None, force_current=False):
     """Refresh widget
     force=False: won't refresh widget if path has not changed"""
     if new_path is None:
         new_path = getcwd()
     if force_current:
         index = self.set_current_folder(new_path)
         self.expand(index)
         self.setCurrentIndex(index)
     self.set_previous_enabled.emit(
                          self.histindex is not None and self.histindex > 0)
     self.set_next_enabled.emit(self.histindex is not None and \
                                self.histindex < len(self.history)-1)
开发者ID:ShenggaoZhu,项目名称:spyder,代码行数:13,代码来源:explorer.py


示例18: setup_page

    def setup_page(self):
        about_label = QLabel(_("The <b>current working directory</b> is "
                    "the working directory for IPython consoles "
                    "and the current directory for the File Explorer."))
        about_label.setWordWrap(True)

        console_group = QGroupBox(_("Console directory"))
        console_label = QLabel(_("The working directory for new consoles is:"))
        console_label.setWordWrap(True)
        console_bg = QButtonGroup(console_group)
        console_project_radio = self.create_radiobutton(
                                _("The current project directory "
                                  "or user home directory "
                                  "(if no project is active)"),
                                'console/use_project_or_home_directory',
                                True,
                                button_group=console_bg)
        console_cwd_radio = self.create_radiobutton(
                                _("The current working directory"),
                                'console/use_cwd',
                                False,
                                button_group=console_bg)

        console_dir_radio = self.create_radiobutton(
                                _("the following directory:"),
                                'console/use_fixed_directory', False,
                                _("The directory when a new console "
                                  "is open will be the specified path"),
                                button_group=console_bg)
        console_dir_bd = self.create_browsedir("", 'console/fixed_directory',
                                               getcwd())
        console_dir_radio.toggled.connect(console_dir_bd.setEnabled)
        console_project_radio.toggled.connect(console_dir_bd.setDisabled)
        console_cwd_radio.toggled.connect(console_dir_bd.setDisabled)
        console_dir_layout = QHBoxLayout()
        console_dir_layout.addWidget(console_dir_radio)
        console_dir_layout.addWidget(console_dir_bd)

        console_layout = QVBoxLayout()
        console_layout.addWidget(console_label)
        console_layout.addWidget(console_project_radio)
        console_layout.addWidget(console_cwd_radio)
        console_layout.addLayout(console_dir_layout)
        console_group.setLayout(console_layout)

        vlayout = QVBoxLayout()
        vlayout.addWidget(about_label)
        vlayout.addSpacing(10)
        vlayout.addWidget(console_group)
        vlayout.addStretch(1)
        self.setLayout(vlayout)
开发者ID:rlaverde,项目名称:spyder,代码行数:51,代码来源:workingdirectory.py


示例19: __init__

    def __init__(self, parent=None, pathlist=None, ro_pathlist=None,
                 not_active_pathlist=None, sync=True):
        QDialog.__init__(self, parent)
        
        # Destroying the C++ object right after closing the dialog box,
        # otherwise it may be garbage-collected in another QThread
        # (e.g. the editor's analysis thread in Spyder), thus leading to
        # a segmentation fault on UNIX or an application crash on Windows
        self.setAttribute(Qt.WA_DeleteOnClose)
        
        assert isinstance(pathlist, list)
        self.pathlist = pathlist
        if not_active_pathlist is None:
            not_active_pathlist = []
        self.not_active_pathlist = not_active_pathlist
        if ro_pathlist is None:
            ro_pathlist = []
        self.ro_pathlist = ro_pathlist
        
        self.last_path = getcwd()
        
        self.setWindowTitle(_("PYTHONPATH manager"))
        self.setWindowIcon(ima.icon('pythonpath'))
        self.resize(500, 300)
        
        self.selection_widgets = []
        
        layout = QVBoxLayout()
        self.setLayout(layout)
        
        top_layout = QHBoxLayout()
        layout.addLayout(top_layout)
        self.toolbar_widgets1 = self.setup_top_toolbar(top_layout)

        self.listwidget = QListWidget(self)
        self.listwidget.currentRowChanged.connect(self.refresh)
        self.listwidget.itemChanged.connect(self.update_not_active_pathlist)
        layout.addWidget(self.listwidget)

        bottom_layout = QHBoxLayout()
        layout.addLayout(bottom_layout)
        self.sync_button = None
        self.toolbar_widgets2 = self.setup_bottom_toolbar(bottom_layout, sync)        
        
        # Buttons configuration
        bbox = QDialogButtonBox(QDialogButtonBox.Close)
        bbox.rejected.connect(self.reject)
        bottom_layout.addWidget(bbox)
        
        self.update_list()
        self.refresh()
开发者ID:rlaverde,项目名称:spyder,代码行数:51,代码来源:pathmanager.py


示例20: save_dictionary

def save_dictionary(data, filename):
    """Save dictionary in a single file .spydata file"""
    filename = osp.abspath(filename)
    old_cwd = getcwd()
    os.chdir(osp.dirname(filename))
    error_message = None
    try:
        saved_arrays = {}
        if load_array is not None:
            # Saving numpy arrays with np.save
            arr_fname = osp.splitext(filename)[0]
            for name in list(data.keys()):
                if isinstance(data[name], np.ndarray) and data[name].size > 0:
                    # Saving arrays at data root
                    fname = __save_array(data[name], arr_fname,
                                       len(saved_arrays))
                    saved_arrays[(name, None)] = osp.basename(fname)
                    data.pop(name)
                elif isinstance(data[name], (list, dict)):
                    # Saving arrays nested in lists or dictionaries
                    if isinstance(data[name], list):
                        iterator = enumerate(data[name])
                    else:
                        iterator = iter(list(data[name].items()))
                    to_remove = []
                    for index, value in iterator:
                        if isinstance(value, np.ndarray) and value.size > 0:
                            fname = __save_array(value, arr_fname,
                                               len(saved_arrays))
                            saved_arrays[(name, index)] = osp.basename(fname)
                            to_remove.append(index)
                    for index in sorted(to_remove, reverse=True):
                        data[name].pop(index)
            if saved_arrays:
                data['__saved_arrays__'] = saved_arrays
        pickle_filename = osp.splitext(filename)[0]+'.pickle'
        with open(pickle_filename, 'wb') as fdesc:
            pickle.dump(data, fdesc, 2)
        tar = tarfile.open(filename, "w")
        for fname in [pickle_filename]+[fn for fn in list(saved_arrays.values())]:
            tar.add(osp.basename(fname))
            os.remove(fname)
        tar.close()
        if saved_arrays:
            data.pop('__saved_arrays__')
    except (RuntimeError, pickle.PicklingError, TypeError) as error:
        error_message = to_text_string(error)
    os.chdir(old_cwd)
    return error_message
开发者ID:rlaverde,项目名称:spyder,代码行数:49,代码来源:iofuncs.py



注:本文中的spyder.py3compat.getcwd函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python py3compat.is_text_string函数代码示例发布时间:2022-05-27
下一篇:
Python main.CONF类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap